[python-win32] Catching SIGBREAK with Python 3.3
Stefan Scherfke
stefan at sofa-rockers.org
Tue Nov 13 21:54:22 CET 2012
Hi Tim,
Am 13.11.2012 um 21:44 schrieb Tim Golden <mail at timgolden.me.uk>:
> On 12/11/2012 13:12, Stefan Scherfke wrote:
>> Hi all,
>>
>> recently I’ve been playing around with sending and catching signals on
>> Windows. I finally found out how to send and catch a BREAK event.
>>
>> With Python 2.7(.2), I only need os.kill(pid, signal.CTRL_C_EVENT) and
>> signal.signal(signal.SIGBREAK, handler). Alternatively, I can use
>> GenerateConsoleCtrlEvent and SetConsoleCtrlHandler via ctypes.
>>
>> However, the former does not work with Python 3.3 (64bit) and the latter
>> always raises a KeyError in Python’s threading module.
>>
>> My question is: Should signal.signal(signal.SIGBREAK, handler) work
>> under Python 3.3? If so, what am I doing wrong? Why raises the
>> ctypes-variant an error while the signal-variant doesn’t?
>
> Possibly unhelpfully, I've just run your code on Python 2.7, 3.3 and 3.4, all of which gave the same output:
>
> parent waiting for child
> child terminating
> parent terminating
>
> This is on WinXP SP3.
did you get this output immediately (within 1 or 2 seconds) or after a while?
The child terminates on its own after 10 seconds, but it shouldn’t get there.
Cheers,
Stefan
>
> That said, there has been quite a bit of activity around the handling of Ctrl-C / Ctrl-Break and KeyboardInterrupt around 3.2 so it wouldn't surprise me if something has changed there.
>
> TJG
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2772 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-win32/attachments/20121113/04a6da65/attachment.bin>
More information about the python-win32
mailing list