8000 bpo-39622: Interrupt the main asyncio task on Ctrl+C by asvetlov · Pull Request #32105 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make interruption stablier
  • Loading branch information
asvetlov committed Mar 25, 2022
commit fb78c7e81a6490e3e940b84917715acc3190b66c
6 changes: 5 additions & 1 deletion Lib/asyncio/runners.py
76C4
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ def _lazy_init(self):
self._state = _State.INITIALIZED

def _on_sigint(self, signum, frame, main_task):
if self._loop is None or self._loop.is_closing():
return
self._interrunt_count += 1
if self._interrunt_count == 1:
if self._interrunt_count == 1 and not main_task.done():
main_task.cancel()
# wakeup a loop if it is blocked by selector.select() with long timeour
self._loop.call_soon_threadsafe(lambda: None)
return
raise KeyboardInterrupt()

Expand Down
0