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 random
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
import subprocess
|
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from subprocess import check_output
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
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):
|
class timeout(contextlib.ContextDecorator):
|
||||||
# Usage: @timeout(seconds) decorator or 'with timeout(seconds):' context manager
|
# 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.seconds = int(seconds)
|
||||||
self.timeout_message = timeout_message
|
self.timeout_message = timeout_msg
|
||||||
self.suppress = bool(suppress_timeout_errors)
|
self.suppress = bool(suppress_timeout_errors)
|
||||||
|
|
||||||
def _timeout_handler(self, signum, frame):
|
def _timeout_handler(self, signum, frame):
|
||||||
@@ -114,7 +114,7 @@ def check_online():
|
|||||||
return False
|
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
|
# Recommend 'git pull' if code is out of date
|
||||||
print(colorstr('github: '), end='')
|
print(colorstr('github: '), end='')
|
||||||
try:
|
try:
|
||||||
@@ -123,9 +123,9 @@ def check_git_status():
|
|||||||
assert check_online(), 'skipping check (offline)'
|
assert check_online(), 'skipping check (offline)'
|
||||||
|
|
||||||
cmd = 'git fetch && git config --get remote.origin.url'
|
cmd = 'git fetch && git config --get remote.origin.url'
|
||||||
url = subprocess.check_output(cmd, shell=True).decode().strip().rstrip('.git') # github repo url
|
url = check_output(cmd, shell=True, timeout=5).decode().strip().rstrip('.git') # git fetch
|
||||||
branch = subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out
|
branch = 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
|
n = int(check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind
|
||||||
if n > 0:
|
if n > 0:
|
||||||
s = f"⚠️ WARNING: code is out of date by {n} commit{'s' * (n > 1)}. " \
|
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."
|
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} ✅'
|
s = f'up to date with {url} ✅'
|
||||||
print(emojis(s)) # emoji-safe
|
print(emojis(s)) # emoji-safe
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(f'{e}{err_msg}')
|
||||||
|
|
||||||
|
|
||||||
def check_python(minimum='3.7.0', required=True):
|
def check_python(minimum='3.7.0', required=True):
|
||||||
@@ -166,7 +166,7 @@ def check_requirements(requirements='requirements.txt', exclude=()):
|
|||||||
n += 1
|
n += 1
|
||||||
print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...")
|
print(f"{prefix} {r} not found and is required by YOLOv5, attempting auto-update...")
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print(f'{prefix} {e}')
|
print(f'{prefix} {e}')
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user