From 57aed88c7a3bc6701a98771c3e358c336cafc147 Mon Sep 17 00:00:00 2001 From: Tim Savannah Date: Sun, 28 May 2017 01:11:42 -0400 Subject: [PATCH] Add 'stop' method (rather than _stopThread) to StoppableThread --- func_timeout/StoppableThread.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/func_timeout/StoppableThread.py b/func_timeout/StoppableThread.py index ebb66cb..a124f42 100644 --- a/func_timeout/StoppableThread.py +++ b/func_timeout/StoppableThread.py @@ -29,6 +29,16 @@ class StoppableThread(threading.Thread): joinThread.start() joinThread._stderr = self._stderr + def stop(self, exception): + ''' + 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) + ''' + return self._stopThread(exception) + + class JoinThread(threading.Thread): ''' JoinThread - The workhouse that stops the StoppableThread