diff --git a/core/cli/main.py b/core/cli/main.py index 35e5b262..d2b5db63 100644 --- a/core/cli/main.py +++ b/core/cli/main.py @@ -39,13 +39,7 @@ async def cleanup(ui: UIBase): def sync_cleanup(ui: UIBase): - loop = None - try: - loop = asyncio.get_running_loop() - except RuntimeError: - asyncio.run(cleanup(ui)) - else: - loop.create_task(cleanup(ui)) + asyncio.run(cleanup(ui)) async def run_project(sm: StateManager, ui: UIBase, args) -> bool: @@ -319,11 +313,23 @@ async def async_main( telemetry.start() - # Set up signal handlers def signal_handler(sig, frame): - if not telemetry_sent: - sync_cleanup(ui) - sys.exit(0) + try: + loop = asyncio.get_running_loop() + + def close_all(): + loop.stop() + sys.exit(0) + + if not telemetry_sent: + cleanup_task = loop.create_task(cleanup(ui)) + cleanup_task.add_done_callback(close_all) + else: + close_all() + except RuntimeError: + if not telemetry_sent: + sync_cleanup(ui) + sys.exit(0) for sig in (signal.SIGINT, signal.SIGTERM): signal.signal(sig, signal_handler) diff --git a/main.py b/main.py index e10d8993..a71fe483 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ import os.path import sys +from sentry_sdk.integrations.asyncio import AsyncioIntegration + try: import sentry_sdk @@ -9,6 +11,7 @@ try: dsn="https://4101633bc5560bae67d6eab013ba9686@o4508731634221056.ingest.us.sentry.io/4508732401909760", send_default_pii=True, traces_sample_rate=1.0, + integrations=[AsyncioIntegration()], ) sentry_sdk.profiler.start_profiler()