From b4612539585c1e9f4e75e0ad084da81f0ad758d3 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 30 Jan 2023 23:55:18 -0500 Subject: make simulator threads pre-emptible --- lib/utils/threading.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/utils/threading.py (limited to 'lib/utils') 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() -- cgit v1.2.3