From f793e36dc64619c6916ae271d5714b9d152cd40f Mon Sep 17 00:00:00 2001 From: Tim Savannah Date: Mon, 13 May 2019 11:24:17 -0400 Subject: [PATCH] StoppableThread - Add more documentation to StoppableThread --- func_timeout/StoppableThread.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/func_timeout/StoppableThread.py b/func_timeout/StoppableThread.py index 0b12412..a05053a 100644 --- a/func_timeout/StoppableThread.py +++ b/func_timeout/StoppableThread.py @@ -52,14 +52,30 @@ class StoppableThread(threading.Thread): joinThread.start() joinThread._stderr = self._stderr + def stop(self, exception, raiseEvery=2.0): ''' Stops the thread by raising a given exception. @param exception - Exception to throw. Likely, you want to use something + that inherits from BaseException (so except Exception as e: continue; isn't a problem) This should be a class/type, NOT an instance, i.e. MyExceptionType not MyExceptionType() + + + @param raiseEvery Default 2.0 - We will keep raising this exception every #raiseEvery seconds, + + until the thread terminates. + + If your code traps a specific exception type, this will allow you #raiseEvery seconds to cleanup before exit. + + If you're calling third-party code you can't control, which catches BaseException, set this to a low number + + to break out of their exception handler. + + + @return ''' return self._stopThread(exception, raiseEvery)