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.

classification
Title: Signal module doesnt raises ValueError Exception
Type: behavior Stage: resolved
Components: Documentation, Windows Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: berker.peksag, brian.curtin, docs@python, flox, python-dev, rsevcan, tim.golden
Priority: low Keywords:

Created on 2014-04-29 08:17 by rsevcan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg217486 - (view) Author: rsevcan (rsevcan) Date: 2014-04-29 08:17
signal.signal() built-in function doesnt throws a ValueError exception in Windows when is called with a different signal than SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, or SIGTERM, as it is written in the documentation.

https://docs.python.org/2/library/signal.html#signal.signal
https://docs.python.org/3/library/signal.html#signal.signal

It throws an AttributeError Exception

>>> import signal
>>> import sys
>>> sys.platform
'win32'
>>> signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'SIGPIPE'
>>>

Regards
msg217531 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2014-04-29 17:16
It's about documentation only.

The sentence is not wrong, but it is slightly confusing, and there's no hint which signals are defined on Windows.

"On Windows, signal() can only be called with SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, or SIGTERM. A ValueError will be raised in any other case."

Reading only this documentation, if the developer doesn't have a test platform on Windows, he could blindly write:

try:
    signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1))
except ValueError:
    pass

... until a Windows user detects the issue (thank you rsevcan)


Now I just found this page which is relevant here ... either we could link to the page in a "See also" section, or give an hint about which signals are defined or not.
http://msdn.microsoft.com/en-us/library/xdkz3x12.aspx
msg217996 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2014-05-06 16:59
To be honest I can't get excited about this one. The only sensible change is to remove the rather specific comment about ValueError and just leave the fact that only certain signals are valid. 

Because the C code defines module-level constants on the basis of whether the platform C-lib defines them, different platforms will have different module attributes. It would be unusual for us to list all the combinations.

Adding Brian Curtin as he made the original change.
msg264077 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-23 23:59
New changeset 1fcf68e6f4c7 by Berker Peksag in branch '3.5':
Issue #21382: Clarify signal.signal() documentation on Windows
https://hg.python.org/cpython/rev/1fcf68e6f4c7

New changeset 3e27b21e3a7d by Berker Peksag in branch 'default':
Issue #21382: Clarify signal.signal() documentation on Windows
https://hg.python.org/cpython/rev/3e27b21e3a7d
History
Date User Action Args
2022-04-11 14:58:02adminsetgithub: 65581
2016-04-23 23:59:58berker.peksagsetstatus: open -> closed
versions: + Python 3.6, - Python 3.4
nosy: + berker.peksag

resolution: fixed
stage: resolved
2016-04-23 23:59:31python-devsetnosy: + python-dev
messages: + msg264077
2014-05-06 16:59:17tim.goldensetnosy: + tim.golden, brian.curtin
messages: + msg217996
2014-04-29 17:16:49floxsetpriority: normal -> low

messages: + msg217531
components: - Library (Lib)
versions: + Python 3.4, Python 3.5
2014-04-29 16:39:02floxsetnosy: + flox
type: enhancement -> behavior
components: + Library (Lib), Windows
2014-04-29 08:17:16rsevcancreate