Skip to content

Commit

Permalink
Add check_git_status() 5 second timeout (ultralytics#3464)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
glenn-jocher authored Jun 4, 2021
1 parent c37f072 commit 563ea94
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
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
Expand All @@ -38,9 +38,9 @@

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):
Expand Down Expand Up @@ -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:
Expand All @@ -123,17 +123,17 @@ 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."
else:
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):
Expand Down Expand Up @@ -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}')

Expand Down

0 comments on commit 563ea94

Please sign in to comment.