summaryrefslogtreecommitdiff
path: root/lib/utils/threading.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2023-01-30 23:55:18 -0500
committerLex Neva <github.com@lexneva.name>2023-02-16 22:54:21 -0500
commitb4612539585c1e9f4e75e0ad084da81f0ad758d3 (patch)
tree75f68fb02a5106363bcd97e984dbe35a0d2c3dab /lib/utils/threading.py
parent30c73dc39c1ac814d0c63ec102c7f8c2b993fdd0 (diff)
make simulator threads pre-emptible
Diffstat (limited to 'lib/utils/threading.py')
-rw-r--r--lib/utils/threading.py21
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()