diff --git a/func_timeout/StoppableThread.py b/func_timeout/StoppableThread.py index 9b8bb3b..b8092e1 100644 --- a/func_timeout/StoppableThread.py +++ b/func_timeout/StoppableThread.py @@ -32,6 +32,7 @@ class StoppableThread(threading.Thread): The exception is raised over and over, with a specifed delay (default 2.0 seconds) ''' + isNestedStoppableThread = None def _stopThread(self, exception, raiseEvery=2.0): @@ -41,6 +42,12 @@ class StoppableThread(threading.Thread): if self.is_alive() is False: return True + currentThread = threading.current_thread() + if issubclass(currentThread.__class__, StoppableThread): + currentThread.isNestedStoppableThread = True + else: + currentThread.isNestedStoppableThread = False + self._stderr = open(os.devnull, 'w') # Create "joining" thread which will raise the provided exception diff --git a/func_timeout/dafunc.py b/func_timeout/dafunc.py index 681a01c..0e8baf0 100644 --- a/func_timeout/dafunc.py +++ b/func_timeout/dafunc.py @@ -68,6 +68,9 @@ def func_timeout(timeout, func, args=(), kwargs=None): ret.append( func(*args2, **kwargs2) ) except FunctionTimedOut: # Don't print traceback to stderr if we time out + currentThread = threading.current_thread() + if getattr(currentThread, 'isNestedStoppableThread', False) is True: + raise pass except Exception as e: exc_info = sys.exc_info()