@@ -1346,7 +1346,6 @@ def __init__(self):
1346
1346
1347
1347
# Start a thread to monitor the time of day and create new shot output
1348
1348
# folders for each day:
1349
- self .output_folder_update_required = threading .Event ()
1350
1349
self .previous_default_output_folder = self .get_default_output_folder ()
1351
1350
inthread (self .rollover_shot_output_folder )
1352
1351
self .non_default_folder = None
@@ -1612,8 +1611,8 @@ def on_select_labscript_file_clicked(self, checked):
1612
1611
self .last_opened_labscript_folder = os .path .dirname (labscript_file )
1613
1612
# Write the file to the lineEdit:
1614
1613
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 ()
1617
1616
1618
1617
def on_edit_labscript_file_clicked (self , checked ):
1619
1618
# get path to text editor
@@ -1654,22 +1653,15 @@ def on_select_shot_output_folder_clicked(self, checked):
1654
1653
self .last_selected_shot_output_folder = os .path .dirname (shot_output_folder )
1655
1654
# Write the file to the lineEdit:
1656
1655
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 ()
1662
1658
1663
1659
def on_reset_shot_output_folder_clicked (self , checked ):
1664
1660
current_default_output_folder = self .get_default_output_folder ()
1665
1661
if current_default_output_folder is None :
1666
1662
return
1667
1663
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 ()
1673
1665
1674
1666
def on_labscript_file_text_changed (self , text ):
1675
1667
# Blank out the 'edit labscript file' button if no labscript file is
@@ -2344,17 +2336,19 @@ def get_default_output_folder(self):
2344
2336
return default_output_folder
2345
2337
2346
2338
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 ."""
2353
2345
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" )
2358
2352
2359
2353
@inmain_decorator ()
2360
2354
def check_output_folder_update (self ):
@@ -3373,7 +3367,7 @@ def make_h5_files(self, labscript_file, output_folder, sequence_globals, shots,
3373
3367
# obtained from new_sequence_details, as it is race-free, whereas the one
3374
3368
# from the UI may be out of date since we only update it once a second.
3375
3369
output_folder = default_output_dir
3376
- self .output_folder_update_required . set ()
3370
+ self .check_output_folder_update ()
3377
3371
run_files = runmanager .make_run_files (
3378
3372
output_folder ,
3379
3373
sequence_globals ,
0 commit comments