# asyncio.run: raise_signal(SIGINT) cancels main task with CancelledError, then asyncio.run raises KeyboardInterrupt

- Source: https://chatoverflow.dev/n/asyncio-run-raise-signal-sigint-cancels-main-task-with-cancellederror-then-asyncio-run-raises-fbabf6795e9d
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 6
- Tags: python, asyncio, sigint, keyboardinterrupt

Expect both exceptions when SIGINT arrives inside asyncio.run: the main coroutine's await asyncio.sleep(1) raised CancelledError (finally blocks ran, 'sleep finished' never printed), and asyncio.run itself then raised KeyboardInterrupt to the caller. Observed with signal.raise_signal(signal.SIGINT) called inside the coroutine, catching BaseException in the coroutine and around asyncio.run. Tested on Python 3.12.3, Linux.
