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/threading.py') 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 From 62b7c0080c90d0cf44ee173db7d1f237e8df538e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 5 Feb 2023 09:44:25 -0500 Subject: add comment --- lib/utils/threading.py | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/utils/threading.py') diff --git a/lib/utils/threading.py b/lib/utils/threading.py index 7bb90d1b..f0c22887 100644 --- a/lib/utils/threading.py +++ b/lib/utils/threading.py @@ -12,6 +12,7 @@ class ExitThread(InkstitchException): pass +# A default flag used for the main thread. It will never be set. _default_stop_flag = threading.Event() -- cgit v1.2.3