fixup analysis signal handling for good

This commit is contained in:
Valentin Boettcher 2022-12-01 14:22:25 -05:00
parent f33900b203
commit 5d901b0878
No known key found for this signature in database
GPG key ID: E034E12B7AF56ACE

View file

@ -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