Implement proper cleanup mechanism

This commit is contained in:
Mark Veidemanis 2022-05-09 08:23:05 +01:00
parent b41f2b8f7f
commit e4c4f1b41f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 27 additions and 6 deletions

View File

@ -28,13 +28,34 @@ Factory.noisy = False
# TODO: extend this with more # TODO: extend this with more
def cleanup(sig, frame): def cleanup(sig, frame):
to_cleanup = []
if hasattr(init_map["money"], "lc_es_checks"):
to_cleanup.append(init_map["money"].lc_es_checks.stop)
if hasattr(init_map["sources"].agora, "lc_dash"):
to_cleanup.append(init_map["sources"].agora.lc_dash.stop)
if hasattr(init_map["sources"].agora, "lc_cheat"):
to_cleanup.append(init_map["sources"].agora.lc_cheat.stop)
if hasattr(init_map["sources"].lbtc, "lc_dash"):
to_cleanup.append(init_map["sources"].lbtc.lc_dash.stop)
if hasattr(init_map["sources"].lbtc, "lc_cheat"):
to_cleanup.append(init_map["sources"].lbtc.lc_cheat.stop)
if hasattr(init_map["sinks"], "truelayer"):
if hasattr(init_map["sinks"].truelayer, "lc"):
to_cleanup.append(init_map["sinks"].truelayer.lc.stop)
if hasattr(init_map["sinks"].truelayer, "lc_tx"):
to_cleanup.append(init_map["sinks"].truelayer.lc_tx.stop)
if hasattr(init_map["sinks"], "nordigen"):
if hasattr(init_map["sinks"].nordigen, "lc"):
to_cleanup.append(init_map["sinks"].nordigen.lc.stop)
if hasattr(init_map["sinks"].nordigen, "lc_tx"):
to_cleanup.append(init_map["sinks"].nordigen.lc_tx.stop)
if init_map: if init_map:
try: for func in to_cleanup:
init_map["tx"].lc_es_checks.stop() try:
init_map["agora"].lc_dash.stop() func()
init_map["agora"].lc_cheat.stop() except: # noqa
except: # noqa print(f"Exception when stopping {func}")
pass # noqa pass # noqa
reactor.stop() reactor.stop()