diff options
Diffstat (limited to 'lib/utils')
| -rw-r--r-- | lib/utils/threading.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/utils/threading.py b/lib/utils/threading.py new file mode 100644 index 00000000..7bb90d1b --- /dev/null +++ b/lib/utils/threading.py @@ -0,0 +1,21 @@ +import threading + +from ..exceptions import InkstitchException +from ..debug import debug + + +class ExitThread(InkstitchException): + """This exception is thrown in a thread to cause it to terminate. + + Presumably we should only catch this at the thread's top level. + """ + pass + + +_default_stop_flag = threading.Event() + + +def check_stop_flag(): + if getattr(threading.current_thread(), 'stop', _default_stop_flag).is_set(): + debug.log("exiting thread") + raise ExitThread() |
