summaryrefslogtreecommitdiff
path: root/lib/gui
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/gui
parent30c73dc39c1ac814d0c63ec102c7f8c2b993fdd0 (diff)
make simulator threads pre-emptible
Diffstat (limited to 'lib/gui')
-rw-r--r--lib/gui/simulator.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py
index 1cc7066e..d9f51b48 100644
--- a/lib/gui/simulator.py
+++ b/lib/gui/simulator.py
@@ -10,6 +10,8 @@ from threading import Event, Thread
import wx
from wx.lib.intctrl import IntCtrl
+from lib.debug import debug
+from lib.utils.threading import ExitThread
from ..i18n import _
from ..stitch_plan import stitch_groups_to_stitch_plan, stitch_plan_from_file
from ..svg import PIXELS_PER_MM
@@ -749,6 +751,10 @@ class SimulatorPreview(Thread):
self.simulate_window = None
self.refresh_needed = Event()
+ # This is read by utils.threading.check_stop_flag() to abort stitch plan
+ # generation.
+ self.stop = Event()
+
# used when closing to avoid having the window reopen at the last second
self._disabled = False
@@ -770,17 +776,27 @@ class SimulatorPreview(Thread):
if not self.is_alive():
self.start()
+ self.stop.set()
self.refresh_needed.set()
def run(self):
while True:
self.refresh_needed.wait()
self.refresh_needed.clear()
- self.update_patches()
+ self.stop.clear()
+
+ try:
+ debug.log("update_patches")
+ self.update_patches()
+ except ExitThread:
+ debug.log("ExitThread caught")
+ self.stop.clear()
def update_patches(self):
try:
patches = self.parent.generate_patches(self.refresh_needed)
+ except ExitThread:
+ raise
except: # noqa: E722
# If something goes wrong when rendering patches, it's not great,
# but we don't really want the simulator thread to crash. Instead,