Skip to content

Commit 54dfa41

Browse files
Merged in cbillington/runmanager/sequence-index-bugfix (pull request labscript-suite#38)
Fix an issue with output folder updating when sequence index changes.
2 parents 658de1d + 4f668be commit 54dfa41

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

__main__.py

+18-24
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,6 @@ def __init__(self):
13461346

13471347
# Start a thread to monitor the time of day and create new shot output
13481348
# folders for each day:
1349-
self.output_folder_update_required = threading.Event()
13501349
self.previous_default_output_folder = self.get_default_output_folder()
13511350
inthread(self.rollover_shot_output_folder)
13521351
self.non_default_folder = None
@@ -1612,8 +1611,8 @@ def on_select_labscript_file_clicked(self, checked):
16121611
self.last_opened_labscript_folder = os.path.dirname(labscript_file)
16131612
# Write the file to the lineEdit:
16141613
self.ui.lineEdit_labscript_file.setText(labscript_file)
1615-
# Tell the output folder thread that the output folder might need updating:
1616-
self.output_folder_update_required.set()
1614+
# Check if the output folder needs to be updated:
1615+
self.check_output_folder_update()
16171616

16181617
def on_edit_labscript_file_clicked(self, checked):
16191618
# get path to text editor
@@ -1654,22 +1653,15 @@ def on_select_shot_output_folder_clicked(self, checked):
16541653
self.last_selected_shot_output_folder = os.path.dirname(shot_output_folder)
16551654
# Write the file to the lineEdit:
16561655
self.ui.lineEdit_shot_output_folder.setText(shot_output_folder)
1657-
# Tell the output folder rollover thread to run an iteration, so that
1658-
# it notices this change (even though it won't do anything now - this
1659-
# is so it can respond correctly if anything else interesting happens
1660-
# within the next second):
1661-
self.output_folder_update_required.set()
1656+
# Update our knowledge about whether this is the default output folder or not:
1657+
self.check_output_folder_update()
16621658

16631659
def on_reset_shot_output_folder_clicked(self, checked):
16641660
current_default_output_folder = self.get_default_output_folder()
16651661
if current_default_output_folder is None:
16661662
return
16671663
self.ui.lineEdit_shot_output_folder.setText(current_default_output_folder)
1668-
# Tell the output folder rollover thread to run an iteration, so that
1669-
# it notices this change (even though it won't do anything now - this
1670-
# is so it can respond correctly if anything else interesting happens
1671-
# within the next second):
1672-
self.output_folder_update_required.set()
1664+
self.check_output_folder_update()
16731665

16741666
def on_labscript_file_text_changed(self, text):
16751667
# Blank out the 'edit labscript file' button if no labscript file is
@@ -2344,17 +2336,19 @@ def get_default_output_folder(self):
23442336
return default_output_folder
23452337

23462338
def rollover_shot_output_folder(self):
2347-
"""Runs in a thread, checking once a second if the default output folder has
2348-
changed, likely because the date has changed. If it is or has, sets the default
2349-
folder in which compiled shots will be put. Does not create the folder if it
2350-
does not already exists, this will be done at compile-time. Will run immediately
2351-
without waiting a full second if the threading.Event
2352-
self.output_folder_update_required is set() from anywhere."""
2339+
"""Runs in a thread, checking every 30 seconds if the default output folder has
2340+
changed, likely because the date has changed, but also possible because another
2341+
instance of runmanager has incremented the sequence index. If the defaulr output
2342+
folder has changed, and if runmanager is configured to use the default output
2343+
folder, sets the folder in which compiled shots will be put. Does not create the
2344+
folder if it does not already exist, this will be done at compile-time."""
23532345
while True:
2354-
# Wait up to one second, shorter if the Event() gets set() by someone:
2355-
self.output_folder_update_required.wait(30)
2356-
self.output_folder_update_required.clear()
2357-
self.check_output_folder_update()
2346+
time.sleep(30)
2347+
try:
2348+
self.check_output_folder_update()
2349+
except Exception as e:
2350+
# Don't stop the thread.
2351+
logger.exception("error checking default output folder")
23582352

23592353
@inmain_decorator()
23602354
def check_output_folder_update(self):
@@ -3373,7 +3367,7 @@ def make_h5_files(self, labscript_file, output_folder, sequence_globals, shots,
33733367
# obtained from new_sequence_details, as it is race-free, whereas the one
33743368
# from the UI may be out of date since we only update it once a second.
33753369
output_folder = default_output_dir
3376-
self.output_folder_update_required.set()
3370+
self.check_output_folder_update()
33773371
run_files = runmanager.make_run_files(
33783372
output_folder,
33793373
sequence_globals,

0 commit comments

Comments
 (0)