Support nested StoppableThreads properly raising exception to correct context

This commit is contained in:
Tim Savannah 2023-04-23 04:15:28 -04:00
parent 50baa8db50
commit cc4c55839d
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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()