glenn-jocher commited on
Commit
3f634d4
1 Parent(s): c09fb2a

Conditional `Timeout()` by OS (disable on Windows) (#7013)

Browse files

* Conditional `Timeout()` by OS (disable on Windows)

* Update general.py

Files changed (1) hide show
  1. utils/general.py +7 -5
utils/general.py CHANGED
@@ -123,13 +123,15 @@ class Timeout(contextlib.ContextDecorator):
123
  raise TimeoutError(self.timeout_message)
124
 
125
  def __enter__(self):
126
- signal.signal(signal.SIGALRM, self._timeout_handler) # Set handler for SIGALRM
127
- signal.alarm(self.seconds) # start countdown for SIGALRM to be raised
 
128
 
129
  def __exit__(self, exc_type, exc_val, exc_tb):
130
- signal.alarm(0) # Cancel SIGALRM if it's scheduled
131
- if self.suppress and exc_type is TimeoutError: # Suppress TimeoutError
132
- return True
 
133
 
134
 
135
  class WorkingDirectory(contextlib.ContextDecorator):
 
123
  raise TimeoutError(self.timeout_message)
124
 
125
  def __enter__(self):
126
+ if platform.system() != 'Windows': # not supported on Windows
127
+ signal.signal(signal.SIGALRM, self._timeout_handler) # Set handler for SIGALRM
128
+ signal.alarm(self.seconds) # start countdown for SIGALRM to be raised
129
 
130
  def __exit__(self, exc_type, exc_val, exc_tb):
131
+ if platform.system() != 'Windows':
132
+ signal.alarm(0) # Cancel SIGALRM if it's scheduled
133
+ if self.suppress and exc_type is TimeoutError: # Suppress TimeoutError
134
+ return True
135
 
136
 
137
  class WorkingDirectory(contextlib.ContextDecorator):