From a6bb00c240df258a05ab729b49dad4bf7631cf8c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 16 Mar 2022 14:23:10 +0100 Subject: [PATCH 1/2] Conditional `Timeout()` by OS (disable on Windows) --- utils/general.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index a7891cbccbab..497e0fde9c67 100755 --- a/utils/general.py +++ b/utils/general.py @@ -123,13 +123,15 @@ def _timeout_handler(self, signum, frame): 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): From 2c08ef872f5550eda39d775c1e340e048cce1ac3 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Wed, 16 Mar 2022 14:26:31 +0100 Subject: [PATCH 2/2] Update general.py --- utils/general.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 497e0fde9c67..e8b3b05c5fe1 100755 --- a/utils/general.py +++ b/utils/general.py @@ -123,12 +123,12 @@ def _timeout_handler(self, signum, frame): raise TimeoutError(self.timeout_message) def __enter__(self): - if platform.system() != 'Windows' # not supported on Windows + 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): - if platform.system() != 'Windows' + 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