classification
Title: Document CTRL_C_EVENT and CTRL_BREAK_EVENT usage on Windows
Type: behavior Stage: needs patch
Components: Documentation, Library (Lib), Windows Versions: Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: brian.curtin Nosy List: brian.curtin, valgog
Priority: normal Keywords:

Created on 2010-08-05 18:21 by valgog, last changed 2010-08-05 19:02 by brian.curtin.

Messages (3)
msg113005 - (view) Author: Valentine Gogichashvili (valgog) Date: 2010-08-05 18:21
When executing the following code on Windows 7 64-bit ::

  import sys
  import signal
  import time
  print 'Version:'
  print sys.executable or sys.platform, sys.version
  print
  print

  def h(s, f): print s

  signal.signal(signal.CTRL_BREAK_EVENT, h)

we get the following output::

  Version:
  C:\Python27\python.exe 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC       v.1500 64 bit (AMD64)]

  Traceback (most recent call last):
  File "signal_ctrl_break_event.py", line 14, in <module>
    signal.signal(signal.CTRL_BREAK_EVENT, h)
  RuntimeError: (0, 'Error')

When trying to register a handler for a signal.CTRL_C_EVENT the exception is as follows::

  File "signal_ctrl_c_event.py", line 6, in <module>
    signal.signal(signal.CTRL_C_EVENT, h)
  ValueError: signal number out of range
msg113006 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-08-05 18:33
Those two signals are only intended to work with os.kill -- they are specific to the GenerateConsoleCtrlEvent function in Modules/posixmodule.c. I'll have to change the documentation to note that.

If you want to send those events to other processes, have a look at os.kill and some example usage in Lib/test/test_os.py and Lib/test/win_console_handler.py. This also needs better documentation.
msg113010 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-08-05 19:02
Fixed the first part, denoting that signal.CTRL_C_EVENT and signal.CTRL_BREAK_EVENT are for os.kill only. Done in r83745 (py3k) and r83746 (release27-maint).

Leaving open for the second part about their usage.
History
Date User Action Args
2010-08-05 19:02:21brian.curtinsetmessages: + msg113010
2010-08-05 18:33:51brian.curtinsetassignee: brian.curtin

components: + Documentation
title: CTRL_C_EVENT and CTRL_BREAK_EVENT cannot be registered by signal.signal() method on windows -> Document CTRL_C_EVENT and CTRL_BREAK_EVENT usage on Windows
nosy: + brian.curtin
versions: + Python 3.2
messages: + msg113006
stage: needs patch
2010-08-05 18:21:44valgogcreate