This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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.4, Python 3.5, Python 2.7
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 2022-04-11 14:57 by admin.

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

  def h(s, f): print s

  signal.signal(signal.CTRL_BREAK_EVENT, h)

we get the following output::

  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 "", 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 "", 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/ and Lib/test/ 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.
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53733
2014-07-10 21:30:59BreamoreBoysetversions: + Python 3.4, Python 3.5, - Python 3.2
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