This commit is contained in:
Zvonimir Sabljic
2025-01-31 20:38:00 +01:00
parent acd9aee275
commit 608001f306
2 changed files with 20 additions and 11 deletions

View File

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

View File

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