22import os
33import queue
44from concurrent .futures import Future
5+ from time import sleep
56from typing import Any , Callable , Optional
67
78from executorlib .standalone .command import get_cache_execute_command
@@ -17,6 +18,7 @@ def __init__(self, file_name: str, selector: Optional[int | str] = None):
1718
1819 Args:
1920 file_name (str): The name of the file.
21+ selector (int | str, optional): The selector to select a specific part of the result. Defaults to None.
2022
2123 """
2224 self ._file_name = file_name
@@ -62,6 +64,7 @@ def execute_tasks_h5(
6264 disable_dependencies : bool = False ,
6365 pmi_mode : Optional [str ] = None ,
6466 wait : bool = True ,
67+ refresh_rate : float = 0.01 ,
6568) -> None :
6669 """
6770 Execute tasks stored in a queue using HDF5 files.
@@ -78,6 +81,7 @@ def execute_tasks_h5(
7881 disable_dependencies (boolean): Disable resolving future objects during the submission.
7982 pmi_mode (str): PMI interface to use (OpenMPI v5 requires pmix) default is None (Flux only)
8083 wait (bool): Whether to wait for the completion of all tasks before shutting down the executor.
84+ refresh_rate (float): The rate at which to refresh the result. Defaults to 0.01.
8185
8286 Returns:
8387 None
@@ -101,6 +105,7 @@ def execute_tasks_h5(
101105 terminate_function = terminate_function ,
102106 pysqa_config_directory = pysqa_config_directory ,
103107 backend = backend ,
108+ refresh_rate = refresh_rate ,
104109 )
105110 if not task_dict ["cancel_futures" ] and wait :
106111 _cancel_processes (
@@ -117,6 +122,7 @@ def execute_tasks_h5(
117122 terminate_function = terminate_function ,
118123 pysqa_config_directory = pysqa_config_directory ,
119124 backend = backend ,
125+ refresh_rate = refresh_rate ,
120126 )
121127 for value in memory_dict .values ():
122128 if not value .done ():
@@ -198,6 +204,7 @@ def execute_tasks_h5(
198204 terminate_function = terminate_function ,
199205 pysqa_config_directory = pysqa_config_directory ,
200206 backend = backend ,
207+ refresh_rate = refresh_rate ,
201208 )
202209
203210
@@ -297,6 +304,7 @@ def _refresh_memory_dict(
297304 terminate_function : Optional [Callable ] = None ,
298305 pysqa_config_directory : Optional [str ] = None ,
299306 backend : Optional [str ] = None ,
307+ refresh_rate : float = 0.01 ,
300308) -> dict :
301309 """
302310 Refresh memory dictionary
@@ -308,6 +316,7 @@ def _refresh_memory_dict(
308316 terminate_function (callable): The function to terminate the tasks.
309317 pysqa_config_directory (str): path to the pysqa config directory (only for pysqa based backend).
310318 backend (str): name of the backend used to spawn tasks.
319+ refresh_rate (float): The rate at which to refresh the result. Defaults to 0.01.
311320
312321 Returns:
313322 dict: Updated memory dictionary
@@ -321,7 +330,7 @@ def _refresh_memory_dict(
321330 pysqa_config_directory = pysqa_config_directory ,
322331 backend = backend ,
323332 )
324- return {
333+ memory_updated_dict = {
325334 key : _check_task_output (
326335 task_key = key ,
327336 future_obj = value ,
@@ -330,6 +339,9 @@ def _refresh_memory_dict(
330339 for key , value in memory_dict .items ()
331340 if not value .done ()
332341 }
342+ if len (memory_updated_dict ) == len (memory_dict ):
343+ sleep (refresh_rate )
344+ return memory_updated_dict
333345
334346
335347def _cancel_processes (
0 commit comments