A script with threads ignores Ctrl-C and must be killed with `kill -9`.
AdvancedTroubleshootingConcurrency, async, tests, services & containers
Answer
Likely causes → The main thread is blocked in join() or executor.shutdown(wait=True) and worker threads (non-daemon) keep running; signals are only delivered to the main thread.
Diagnose → py-spy dump --pid <pid> shows the main thread waiting in join.
Fix → Use a threading.Event checked by workers; in the main thread, wait with timeouts (as_completed(..., timeout=...) loops or event.wait(1)), catch KeyboardInterrupt, set the event, and shutdown(cancel_futures=True).
Prevent → Build cooperative cancellation into long-running workers from day one.
More on Concurrency, async, tests, services & containers
`RuntimeError: asyncio.run() cannot be called from a running event loop` in a Jupyter notebook or inside an async framework.Intermediate`RuntimeWarning: coroutine 'fetch' was never awaited` and nothing happens.BeginnerAn asyncio health-checker is no faster than a sequential loop.Advanced`Task was destroyed but it is pending!` at shutdown.Advanced`OSError: [Errno 24] Too many open files` from an asyncio scanner with 20,000 targets.IntermediateA `ThreadPoolExecutor` job finishes "successfully" but half the work is missing, with no errors logged.Intermediate