classification
Title: [Windows] asyncio: support signal handlers on Windows (feature request)
Type: enhancement Stage: resolved
Components: asyncio, Windows Versions: Python 3.8
process
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 2019-01-05 20:45 by asvetlov. 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 http://stackoverflow.com/questions/27480967/why-does-the-asyncios-event-loop-suppress-the-keyboardinterrupt-on-windows 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:
https://code.google.com/p/tulip/issues/detail?id=191

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 https://github.com/python/tulip/issues/191 .
msg246316 - (view) Author: Adam Bartoš (Drekin) * Date: 2015-07-05 14:24
I've also run into this issue (see https://mail.python.org/pipermail/python-list/2015-July/693496.html 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()
loop.run_until_complete(wait())

---

The following even smaller example by Terry Reedy and the OP from http://stackoverflow.com/questions/27480967/why-does-the-asyncios-event-loop-suppress-the-keyboardinterrupt-on-windows cannot be interrupted other way then shuting down whole process:

asyncio.get_event_loop().run_forever()

---

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:
https://docs.python.org/3/library/asyncio-protocol.html#protocol-examples
I copied the two examples from the docs into `server.py' and `client.py'. I ran server.py first and hit control-C. This did not close the server as expected. However, if I then ran client.py, 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)
https://github.com/python/cpython/commit/b5c8cfa1da17c6f3acac80a0afca7f7104fb9589
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)
https://github.com/python/cpython/commit/67ba547cf001d6b975cf6900aaf2bd5508dc6a87
History
Date User Action Args
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