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
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:
try:
init_map["tx"].lc_es_checks.stop()
init_map["agora"].lc_dash.stop()
init_map["agora"].lc_cheat.stop()
except: # noqa
pass # noqa
for func in to_cleanup:
try:
func()
except: # noqa
print(f"Exception when stopping {func}")
pass # noqa
reactor.stop()