This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: asyncio.Event.wait() Task was destroyed but it is pending
Type: Stage: resolved
Components: asyncio Versions: Python 3.4
Status: closed Resolution: duplicate
Dependencies: Superseder: Handle KeyboardInterrupt in asyncio
View: 39622
Assigned To: Nosy List: asvetlov, gvanrossum, matt, mpaolini, vstinner, yselivanov
Priority: normal Keywords:

Created on 2015-04-30 13:59 by matt, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit matt, 2015-04-30 13:59 Test case
Messages (3)
msg242269 - (view) Author: Matt Johnston (matt) Date: 2015-04-30 13:59
asyncio.Event.wait() doesn't seem to be cancelled by asyncio.wait_for(). Ctrl-c in the attached example produces output below. I'm not certain the code is correct though the documentation for wait_for() suggests it should work. Without the wait_for() it doesn't suffer from pending task destruction. This is Python 3.4.3. 

Hello World!
Hello World!
^CTraceback (most recent call last):
  File "./", line 27, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/", line 304, in run_until_complete
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/", line 276, in run_forever
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/", line 1136, in _run_once
    event_list =
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/", line 502, in select
    kev_list = self._kqueue.control(None, max_ev, timeout)
Task was destroyed but it is pending!
task: <Task pending coro=<wait() running at /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/> wait_for=<Future pending cb=[Task._wakeup()]> cb=[_release_waiter(<Future]>)() at /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/]>
[1]    8134 exit 1     ../venv3/bin/python3 ./
msg242287 - (view) Author: Marco Paolini (mpaolini) * Date: 2015-04-30 20:34
KeyboardInterrupt is not handled gently by asyncio (see

you could cancel all tasks in the signal handler:


def sig_interrupt():
    for task in asyncio.Task.all_tasks():

loop.add_signal_handler(signal.SIGINT, sig_interrupt)
msg415425 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-17 16:32
Duplicate for #39622
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68268
2022-03-17 16:32:46asvetlovsetstatus: open -> closed
superseder: Handle KeyboardInterrupt in asyncio
messages: + msg415425

resolution: duplicate
stage: resolved
2022-03-17 00:18:42iritkatrielsetnosy: + asvetlov
2015-04-30 20:34:45mpaolinisetnosy: + mpaolini
messages: + msg242287
2015-04-30 13:59:58mattcreate