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: [Windows] asyncio: support signal handlers on Windows (feature request)
Type: enhancement Stage: resolved
Components: asyncio, Windows Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: David Robertson, Drekin, Kimmo.Parviainen-Jalanko, Kwpolska, akuchling, asvetlov, jkloth, steve.dower, tim.golden, vstinner, yselivanov, zach.ware
Priority: normal Keywords: patch

Created on 2014-12-15 20:10 by asvetlov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11135 merged v2m, 2018-12-13 00:36
PR 11274 merged cheryl.sabella, 2018-12-22 21:26
Messages (12)
msg232678 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2014-12-15 20:10
See for details
msg232770 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-16 23:43
Hi, I started to work on this topic a few months ago:

I should update my patches.
msg232772 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-16 23:46
This issue is specific to Windows. On all others platforms, signal handling is nicely supported.
msg232865 - (view) Author: Kimmo Parviainen-Jalanko (Kimmo.Parviainen-Jalanko) Date: 2014-12-18 09:30
Seems to happen on FreeBSD 10.1 as well with 3.4.2
msg232866 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-12-18 09:37
> Seems to happen on FreeBSD 10.1 as well with 3.4.2

FreeBSD uses a completly different implementation. Please open a new issue, describe your problem and write a script reproducing your issue.
msg240645 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2015-04-13 16:29
Victor's patch has moved to .
msg246316 - (view) Author: Adam Bartoš (Drekin) * Date: 2015-07-05 14:24
I've also run into this issue (see and the following thread). I'm adding some small examples showing the behavior.

import asyncio

async def wait():
    await asyncio.sleep(5)

loop = asyncio.get_event_loop()


The following even smaller example by Terry Reedy and the OP from cannot be interrupted other way then shuting down whole process:



It would be nice the patch mentioned was eventually applied.
msg246428 - (view) Author: David Robertson (David Robertson) Date: 2015-07-07 16:27
Dear all, I have just been trying to understand the TCP Echo example from the asyncio documentation:
I copied the two examples from the docs into `' and `'. I ran first and hit control-C. This did not close the server as expected. However, if I then ran, the act of sending a message to the server seemed to prompt it to receive the KeyboardInterrupt and close! In turn this caused an OSError to be raised by the client.

Some searching lead me to StackOverflow and then to this bug. I wanted to point out this behaviour, as I didn't see it mentioned in any of the previous comments. Plus, I thought it was a shame that the first example I looked didn't behave as described!

I'm curently running Python 3.3.1 on Windows 7 and I'm using asyncio 3.4.3 from PyPI.
msg246441 - (view) Author: Adam Bartoš (Drekin) * Date: 2015-07-07 19:33
David Robertson: The behaviour you pointed out is a consequence of the general issue: signals on Windows aren't fully supported. Basically, they cannot interrupt the event loop when every coroutine is waiting for something. Instead, they are fired when something happens – some data are recieved or some timer reaches zero. In your case it was the connection of the client or the message it sent.

This is the right issue related to your problem. Hopefully, it will be fixed eventually. A current workaround is to schedule a task which periodically sleeps for an amount of time. For example, if it allways sleeps for one second, then you will wait for KeyboardInterrupt at most one second.
msg332088 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-12-18 21:56
New changeset b5c8cfa1da17c6f3acac80a0afca7f7104fb9589 by Andrew Svetlov (Vladimir Matveev) in branch 'master':
bpo-23057: add loop self socket as wakeup fd for signals (#11135)
msg332769 - (view) Author: Jeremy Kloth (jkloth) * Date: 2018-12-30 22:52
GH-11274 desperately needs to be addressed! The 2 Windows 7 buildbots have been failing on 3.x since the merge of GH-11135 on 12-18. Either that or the commit b5c8cfa needs to be reverted.

Being the holiday season and all I can see the extra time needed for Python development is sparse, but 2 weeks without ensuring a commit doesn't break stable buildbots seems a bit much.
msg333073 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-01-05 20:45
New changeset 67ba547cf001d6b975cf6900aaf2bd5508dc6a87 by Andrew Svetlov (Vladimir Matveev) in branch 'master':
bpo-23057: Use 'raise' to emulate ctrl-c in proactor tests (#11274)
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67246
2019-01-15 12:24:11vstinnerlinkissue32661 superseder
2019-01-05 20:45:03asvetlovsetmessages: + msg333073
2018-12-31 02:06:56gvanrossumsetnosy: - gvanrossum
2018-12-30 22:52:15jklothsetnosy: + jkloth
messages: + msg332769
2018-12-22 21:26:07cheryl.sabellasetpull_requests: + pull_request10519
2018-12-18 21:58:01asvetlovsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.8, - Python 3.6, Python 3.7
2018-12-18 21:56:19asvetlovsetmessages: + msg332088
2018-12-13 00:36:47v2msetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request10367
2018-09-07 18:36:55Kwpolskasetnosy: + Kwpolska
2017-09-02 00:57:30eryksunsetstage: needs patch
versions: + Python 3.6, Python 3.7, - Python 3.4, Python 3.5
2015-07-07 19:33:58Drekinsetmessages: + msg246441
2015-07-07 16:27:34David Robertsonsetnosy: + David Robertson
messages: + msg246428
2015-07-05 14:24:36Drekinsetnosy: + Drekin
messages: + msg246316
2015-04-13 16:29:42akuchlingsetnosy: + akuchling
messages: + msg240645
2015-01-26 14:23:05vstinnersettype: behavior -> enhancement
title: asyncio loop on Windows should stop on keyboard interrupt -> [Windows] asyncio: support signal handlers on Windows (feature request)
2014-12-18 09:37:05vstinnersetmessages: + msg232866
2014-12-18 09:30:15Kimmo.Parviainen-Jalankosetnosy: + Kimmo.Parviainen-Jalanko
messages: + msg232865
2014-12-16 23:46:45vstinnersetnosy: + tim.golden, zach.ware, steve.dower
messages: + msg232772
components: + Windows
2014-12-16 23:43:58vstinnersetmessages: + msg232770
2014-12-15 20:10:56asvetlovcreate