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: AttributeError: module 'signal' has no attribute 'SIGHUP'
Type: compile error Stage: resolved
Components: Windows Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ametatheton2, eryksun, iritkatriel, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-01-18 20:48 by ametatheton2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
unknown (2).png ametatheton2, 2021-01-18 20:48 A picture of the error I get upon running the file.
Messages (3)
msg385227 - (view) Author: Joel Ewaldo (ametatheton2) Date: 2021-01-18 20:48
I have already tried uninstalling and reinstalling python 3.7.9 via the 64-bit installer on the official python website. Also, I am on the latest version of windows. I have also made sure that signal.py was not a file in my directory and when I import _signal followed with print(dir(_signal)), it returns ['CTRL_BREAK_EVENT', 'CTRL_C_EVENT', 'NSIG', 'SIGABRT', 'SIGBREAK', 'SIGFPE', 'SIGILL', 'SIGINT', 'SIGSEGV', 'SIGTERM', 'SIG_DFL', 'SIG_IGN', '__doc__', '__loader__', '__name__', '__package__', 
'__spec__', 'default_int_handler', 'getsignal', 'set_wakeup_fd', 'signal'].
msg385228 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-18 20:58
As the docs explain, SIGHUP is not available on Windows. This is as designed.
msg385237 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-01-18 22:38
FYI, Windows is not a POSIX operating system and does not implement Unix signals in the kernel. That said, the C language serves as a base level of cross-platform support for language runtimes across most operating systems, and there's significant coupling between C and Unix. Standard C requires six Unix signals to be supported in some fashion: SIGABRT, SIGTERM, SIGFPE, SIGILL, SIGSEGV, and SIGINT. 

The C runtime in Windows implements SIGABRT and SIGTERM only within the process, e.g. with C raise() and abort(). There's no mechanism to send these signals to another process. It implements SIGFPE, SIGILL, SIGSEGV using an OS structured exception handler, but these can't and shouldn't be handled in Python. 

That leaves SIGINT, which is implemented for console applications using a console control handler for the cancel event (CTRL_C_EVENT). The same handler also implements non-standard SIGBREAK for the other console control events: break, close, logoff, and shutdown. 

There's limited support to send the cancel and break events (CTRL_C_EVENT and CTRL_BREAK_EVENT) to other processes via WinAPI GenerateConsoleCtrlEvent(ctrlEvent, processGroupId). The event can be sent to a process group in the current console session or to all processes (group 0) in the console session. The process group ID (pgid) of a process cannot be directly queried. The only way to know a pgid is to create a process as the leader of a new group with the creation flag CREATE_NEW_PROCESS_GROUP, in which case the pgid is the pid. A new process group initially has the cancel event ignored, until a process manually enables it. So in practice you can only rely on sending the break event. This is implemented in Python via os.kill(pgid, event) and subprocess.Popen.send_signal(event). But remember the target pgid must be either 0 or a known pgid. Using a pid that's not a pgid has undefined behavior.
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87125
2021-09-06 10:59:28iritkatrielsetpull_requests: - pull_request26608
2021-09-06 10:58:00iritkatrielsetnosy: + iritkatriel

pull_requests: + pull_request26608
2021-01-19 01:14:47gvanrossumsetnosy: - gvanrossum
2021-01-18 22:38:05eryksunsetnosy: + eryksun
messages: + msg385237
2021-01-18 20:58:57gvanrossumsetstatus: open -> closed

nosy: + gvanrossum
messages: + msg385228

resolution: not a bug
stage: resolved
2021-01-18 20:48:11ametatheton2create