Am 14.11.2012 um 13:58 schrieb Tim Golden <m...@timgolden.me.uk>: > On 13/11/2012 20:54, Stefan Scherfke wrote: >> Hi Tim, >> >> Am 13.11.2012 um 21:44 schrieb Tim Golden <m...@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? > > And just a little more data. I've run a slightly modified version of > your code on a Win7 box with the same results. Slightly modified because > I realised that your subprocess.call was calling "python" which would be > running 2.7 on my box. I modified it to call sys.executable and added a > print(sys.version) at the top of the parent & child. I also added a line > to indicate that the child had finished sleeping rather than having been > signalled. > > It worked as expected for 2.7, 3.2, 3.3 & 3.4 > > 3.3 & 3.4 were slightly slower to respond. That might be due to a change > to the interpreter loop to avoid a (slightly obscure) race condition > when Ctrl-C was pressed.
It seems like the sleep()-call cannot be interrupted. I added the changes you described to my code. Under XP, Py33 32bit, the child process takes 10s to terminate but doesn’t prints the last message. If I replace the sleep(10) call with a "for i in range(10): sleep(1)", the child terminates after the first call. Python 2.7 (32bit, winxp) however can interrupt the sleep(10)-call immediately. Cheers, Stefan > > TJG > _______________________________________________ > python-win32 mailing list > python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32