Add check_git_status() 5 second timeout (#3464)
* Add check_git_status() 5 second timeout This should prevent the SSH Git bug that we were discussing @KalenMike * cleanup * replace timeout with check_output built-in timeout
This commit is contained in:
1 parent
c37f072ba7
commit
563ea9475a
1 file changed
+9
-9
+9
-9
@@ -9,12 +9,12 @@ import platform
|
||||
import random
|
||||
import re
|
||||
import signal
|
||||
import subprocess
|
||||
import time
|
||||
import urllib
|
||||
from itertools import repeat
|
||||
from multiprocessing.pool import ThreadPool
|
||||
from pathlib import Path
|
||||
from subprocess import check_output
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
@@ -38,9 +38,9 @@ os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max t
|
||||
|
||||
class timeout(contextlib.ContextDecorator):
|
||||
# Usage: @timeout(seconds) decorator or 'with timeout(seconds):' context manager
|
||||
def __init__(self, seconds, *, timeout_message="", suppress_timeout_errors=True):
|
||||
def __init__(self, seconds, *, timeout_msg='', suppress_timeout_errors=True):
|
||||
self.seconds = int(seconds)
|
||||
self.timeout_message = timeout_message
|
||||
self.timeout_message = timeout_msg
|
||||
self.suppress = bool(suppress_timeout_errors)
|
||||
|
||||
def _timeout_handler(self, signum, frame):
|
||||
@@ -114,7 +114,7 @@ def check_online():
|
||||
return False
|
||||
|
||||
|
||||
def check_git_status():
|
||||
def check_git_status(err_msg=', for updates see https://github.com/ultralytics/yolov5'):
|
||||
# Recommend 'git pull' if code is out of date
|
||||
print(colorstr('github: '), end='')
|
||||
try:
|
||||
@@ -123,9 +123,9 @@ def check_git_status():
|
||||
assert check_online(), 'skipping check (offline)'
|
||||
|
||||
cmd = 'git fetch && git config --get remote.origin.url'
|
||||
url = subprocess.check_output(cmd, shell=True).decode().strip().rstrip('.git') # github repo url
|
||||
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out
|
||||
n = int(subprocess.check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind
|
||||
url = check_output(cmd, shell=True, timeout=5).decode().strip().rstrip('.git') # git fetch
|
||||
branch = check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out
|
||||
n = int(check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind
|
||||
if n > 0:
|
||||
s = f"⚠️ WARNING: code is out of date by {n} commit{'s' * (n > 1)}. " \
|
||||
f"Use 'git pull' to update or 'git clone {url}' to download latest."
|
||||
@@ -133,7 +133,7 @@ def check_git_status():
|
||||
s = f'up to date with {url} ✅'
|
||||
print(emojis(s)) # emoji-safe
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(f'{e}{err_msg}')
|
||||
|
||||
|
||||
def check_python(minimum='3.7.0', required=True):
|
||||
@@ -166,7 +166,7 @@ def check_requirements(requirements='requirements.txt', exclude=()):
|
||||
n += 1
|
||||
print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...")
|
||||
try:
|
||||
print(subprocess.check_output(f"pip install '{r}'", shell=True).decode())
|
||||
print(check_output(f"pip install '{r}'", shell=True).decode())
|
||||
except Exception as e:
|
||||
print(f'{prefix} {e}')
|
||||
|
||||
|
||||
Reference in new issue
Block a user