New TryExcept decorator (#9154)
* New TryExcept decorator * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
f0e5a608f5
commit
d07ddc6996
4 files changed
+69
-59
No files matched your search
+3
-24
@@ -15,7 +15,6 @@ import re
|
||||
import shutil
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import urllib
|
||||
from datetime import datetime
|
||||
@@ -34,6 +33,7 @@ import torch
|
||||
import torchvision
|
||||
import yaml
|
||||
|
||||
from utils import TryExcept
|
||||
from utils.downloads import gsutil_getsize
|
||||
from utils.metrics import box_iou, fitness
|
||||
|
||||
@@ -195,27 +195,6 @@ class WorkingDirectory(contextlib.ContextDecorator):
|
||||
os.chdir(self.cwd)
|
||||
|
||||
|
||||
def try_except(func):
|
||||
# try-except function. Usage: @try_except decorator
|
||||
def handler(*args, **kwargs):
|
||||
try:
|
||||
func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
return handler
|
||||
|
||||
|
||||
def threaded(func):
|
||||
# Multi-threads a target function and returns thread. Usage: @threaded decorator
|
||||
def wrapper(*args, **kwargs):
|
||||
thread = threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True)
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def methods(instance):
|
||||
# Get class/instance methods
|
||||
return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith("__")]
|
||||
@@ -319,7 +298,7 @@ def git_describe(path=ROOT): # path must be a directory
|
||||
return ''
|
||||
|
||||
|
||||
@try_except
|
||||
@TryExcept()
|
||||
@WorkingDirectory(ROOT)
|
||||
def check_git_status(repo='ultralytics/yolov5'):
|
||||
# YOLOv5 status check, recommend 'git pull' if code is out of date
|
||||
@@ -364,7 +343,7 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals
|
||||
return result
|
||||
|
||||
|
||||
@try_except
|
||||
@TryExcept()
|
||||
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=()):
|
||||
# Check installed dependencies meet YOLOv5 requirements (pass *.txt file or list of packages)
|
||||
prefix = colorstr('red', 'bold', 'requirements:')
|
||||
|
||||
Reference in new issue
Block a user