| 44 | print(f"[Main] Cleanup timeout ({cleanup_timeout_seconds}s), skipping remaining cleanup.") |
| 45 | |
| 46 | async def _cancel_remaining_tasks(timeout_seconds: float = 2.0) -> None: |
| 47 | current = asyncio.current_task() |
| 48 | tasks = [t for t in asyncio.all_tasks() if t is not current and not t.done()] |
| 49 | if not tasks: |
| 50 | return |
| 51 | for t in tasks: |
| 52 | t.cancel() |
| 53 | try: |
| 54 | await asyncio.wait_for( |
| 55 | asyncio.gather(*tasks, return_exceptions=True), |
| 56 | timeout=timeout_seconds, |
| 57 | ) |
| 58 | except asyncio.TimeoutError: |
| 59 | pass |
| 60 | |
| 61 | async def _runner() -> None: |
| 62 | loop = asyncio.get_running_loop() |