Nathaniel Smith added the comment:

> A real Ctrl+C executes the registered control handlers for the process.

Right, but it's *extremely* unusual for a python 3 program to have a control 
handler registered directly via SetConsoleCtrlHandler. This isn't an API that 
the interpreter uses or exposes. The vast majority of programs receive 
control-C notification by letting the C runtime convert the low level console 
event into a SIGINT, and then receiving this via the signal module.

> To emulate this, PyErr_SetInterrupt could try calling 
> GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0) to broadcast a Ctrl+C event. 

But as mentioned up thread, this is really flaky - and even when it works it 
tends to kill random other processes, which is *certainly* not what anyone 
expects from calling interrupt_main. You can't really call it experimentally – 
even trying to call it can do stuff like cause appveyor tests to lock up.

Given these two issues, I think that emulating control-C at the signal level 
makes the best tradeoffs. Something that works 100% reliably for 99.99% of 
python programs is way better than something that is 80% reliable for 100% of 
programs.

> One problem is that GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0) doesn't cancel 
> a blocking console read like Ctrl+C does. Python's C handler could call 
> CancelSynchronousIo(hMainThread) to address this problem in general. 
> Unfortunately, when a console read is canceled in the client, it isn't 
> canceled in the console itself. The contents of the read will be discarded, 
> but it's a bit clunky that the user has to press enter.

This might be something to address as a separate issue? I'm guessing this 
doesn't affect idle, and it doesn't affect time.sleep, which seem to be the 
main topics of this thread, plus it sounds like any solution would be mostly 
orthogonal.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29926>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to