From e4c4f1b41f3a17f842c972e836f992aef3ea9b16 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 9 May 2022 08:23:05 +0100 Subject: [PATCH] Implement proper cleanup mechanism --- handler/app.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/handler/app.py b/handler/app.py index 4cbc6cd..9e5f05e 100755 --- a/handler/app.py +++ b/handler/app.py @@ -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()