2023-01-31 04:55:18 +00:00
|
|
|
import threading
|
|
|
|
|
|
|
|
from ..exceptions import InkstitchException
|
2024-05-11 06:14:40 +00:00
|
|
|
from ..debug.debug import debug
|
2023-01-31 04:55:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-02-05 14:44:25 +00:00
|
|
|
# A default flag used for the main thread. It will never be set.
|
2023-01-31 04:55:18 +00:00
|
|
|
_default_stop_flag = threading.Event()
|
|
|
|
|
|
|
|
|
|
|
|
def check_stop_flag():
|
2023-10-21 16:16:34 +00:00
|
|
|
# This getattr() actually looks at the PreviewRenderer instance's stop attribute.
|
2023-01-31 04:55:18 +00:00
|
|
|
if getattr(threading.current_thread(), 'stop', _default_stop_flag).is_set():
|
|
|
|
debug.log("exiting thread")
|
|
|
|
raise ExitThread()
|