mirror of
https://github.com/ultralytics/yolov5.git
synced 2025-06-03 14:49:29 +08:00
Conditional Timeout()
by OS (disable on Windows) (#7013)
* Conditional `Timeout()` by OS (disable on Windows) * Update general.py
This commit is contained in:
parent
c09fb2aa95
commit
3f634d43c8
@ -123,13 +123,15 @@ class Timeout(contextlib.ContextDecorator):
|
||||
raise TimeoutError(self.timeout_message)
|
||||
|
||||
def __enter__(self):
|
||||
signal.signal(signal.SIGALRM, self._timeout_handler) # Set handler for SIGALRM
|
||||
signal.alarm(self.seconds) # start countdown for SIGALRM to be raised
|
||||
if platform.system() != 'Windows': # not supported on Windows
|
||||
signal.signal(signal.SIGALRM, self._timeout_handler) # Set handler for SIGALRM
|
||||
signal.alarm(self.seconds) # start countdown for SIGALRM to be raised
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
signal.alarm(0) # Cancel SIGALRM if it's scheduled
|
||||
if self.suppress and exc_type is TimeoutError: # Suppress TimeoutError
|
||||
return True
|
||||
if platform.system() != 'Windows':
|
||||
signal.alarm(0) # Cancel SIGALRM if it's scheduled
|
||||
if self.suppress and exc_type is TimeoutError: # Suppress TimeoutError
|
||||
return True
|
||||
|
||||
|
||||
class WorkingDirectory(contextlib.ContextDecorator):
|
||||
|
Loading…
x
Reference in New Issue
Block a user