Make StoppableThread.JoinThread have a configurable retry interval (still default 2 seconds). Will attempt to retry stopping thread every this-many seconds

This commit is contained in:
Tim Savannah 2017-05-20 17:20:23 -04:00
parent e554cd0252
commit d6ff5e1932

View File

@ -32,15 +32,16 @@ class JoinThread(threading.Thread):
JoinThread - The workhouse that stops the StoppableThread
'''
def __init__(self, otherThread, exception):
def __init__(self, otherThread, exception, repeatEvery=2.0):
threading.Thread.__init__(self)
self.otherThread = otherThread
self.exception = exception
self.repeatEvery = repeatEvery
self.daemon = True
def run(self):
while self.otherThread.isAlive():
# We loop raising exception incase it's caught hopefully this breaks us far out.
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.otherThread.ident), ctypes.py_object(self.exception))
self.otherThread.join(2)
self.otherThread.join(self.repeatEvery)