Skip to content

Commit 885ed42

Browse files
Merged in cbillington/labscript_devices/bugfix (pull request #77)
Fix a deadlock restarting IMAQdxCamera.
2 parents e1873d0 + 06fdbd3 commit 885ed42

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

IMAQdxCamera/blacs_tabs.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616
from time import perf_counter
1717
import ast
18+
from queue import Empty
1819

1920
import labscript_utils.h5_lock
2021
import h5py
@@ -72,11 +73,23 @@ def handler(self, data):
7273
self.last_frame_time = this_frame_time
7374
# Wait for the previous update to compete so we don't accumulate a backlog:
7475
if self.update_event is not None:
75-
self.update_event.get()
76+
while True:
77+
# Don't block, and check for self.stopping regularly in case we are
78+
# shutting down. Otherwise if shutdown is called from the main thread we
79+
# would deadlock.
80+
try:
81+
self.update_event.get(timeout=0.1)
82+
break
83+
except Empty:
84+
if self.stopping:
85+
return
7686
self.update_event = inmain_later(self.update, image, self.frame_rate)
7787
return [b'ok']
7888

7989
def update(self, image, frame_rate):
90+
if not self.mainloop_thread.is_alive():
91+
# We have been shut down. Nothing to do here.
92+
return
8093
if self.image_view.image is None:
8194
# First time setting an image. Do autoscaling etc:
8295
self.image_view.setImage(image.T)

0 commit comments

Comments
 (0)