mirror of
https://github.com/vale981/two_qubit_model
synced 2025-03-05 09:41:41 -05:00
fixup analysis signal handling for good
This commit is contained in:
parent
f33900b203
commit
5d901b0878
1 changed files with 29 additions and 25 deletions
|
@ -146,35 +146,28 @@ def integrate(
|
|||
analyze_kwargs = dict()
|
||||
|
||||
logging.info("Starting analysis process.")
|
||||
analysis_process = Process(
|
||||
target=lambda: model.all_energies_online(
|
||||
|
||||
def target():
|
||||
for sgn in [signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGUSR1]:
|
||||
signal.signal(sgn, signal.SIG_IGN)
|
||||
|
||||
model.all_energies_online(
|
||||
stream_pipe=stream_file,
|
||||
results_directory=results_path,
|
||||
**analyze_kwargs,
|
||||
)
|
||||
)
|
||||
|
||||
analysis_process = Process(target=target)
|
||||
|
||||
analysis_process.start()
|
||||
logging.info(f"Started analysis process with pid {analysis_process.pid}.")
|
||||
|
||||
def signal_handler(_):
|
||||
def cleanup(_):
|
||||
del _
|
||||
|
||||
if analysis_process is not None:
|
||||
analysis_process.join()
|
||||
|
||||
with signal_delay.sig_delay(
|
||||
[signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGUSR1],
|
||||
signal_handler,
|
||||
):
|
||||
if single_process:
|
||||
supervisor.integrate_single_process(clear_pd)
|
||||
else:
|
||||
supervisor.integrate(clear_pd)
|
||||
|
||||
if analysis_process:
|
||||
analysis_process.join()
|
||||
|
||||
with supervisor.get_data(True, stream=False) as data:
|
||||
with model_db(data_path) as db:
|
||||
dct = {
|
||||
|
@ -193,6 +186,17 @@ def integrate(
|
|||
|
||||
db[hash] = dct
|
||||
|
||||
with signal_delay.sig_delay(
|
||||
[signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGUSR1],
|
||||
cleanup,
|
||||
):
|
||||
if single_process:
|
||||
supervisor.integrate_single_process(clear_pd)
|
||||
else:
|
||||
supervisor.integrate(clear_pd)
|
||||
|
||||
cleanup(0)
|
||||
|
||||
|
||||
def get_data(
|
||||
model: Model, data_path: str = "./.data", read_only: bool = True, **kwargs
|
||||
|
|
Loading…
Add table
Reference in a new issue