subprocess_runner
This file contains some utilities that are useful to run a function inside an independent sub-process.
When the subprocess is finished the memory is fully released, which is useful to avoid memory leaks, especially from tensorflow.
- tensiometer.utilities.subprocess_runner.run_in_process(**kwargs)[source]
Decorator to run a function in a subprocess with optional feedback, monitoring, and timeout capabilities.
- Parameters:
- kwargs (dict): Overrides for default settings. Valid keys are:
‘subprocess’ (bool): Whether to run the function in a subprocess.
‘feedback_level’ (int): Feedback verbosity level (0 to 3).
‘context’ (str): Multiprocessing context (‘fork’, ‘spawn’, ‘forkserver’).
‘monitoring’ (bool): Enable/disable monitoring.
‘monitoring_frequency’ (int): Monitoring update frequency in seconds.
‘timeout’ (int or None): Maximum allowed runtime in seconds.
- Returns:
function: A wrapped version of the input function with subprocess capabilities.