python模块'信号'没有属性'SIGHUP'和其他信号

C02TPARXG8WN:fal$ python
Python 3.6.9 (default,Nov 10 2019,01:00:31) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)] on darwin
Type "help","copyright","credits" or "license" for more information.
>>> import signal
>>> signal.SIGHUP
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
AttributeError: module 'signal' has no attribute 'SIGHUP'
>>> 

在macOS上的测试信号。无法弄清楚为什么持续出现吸气信号错误

C02TPARXG8WN:~ fc$ trap -l

1)SIGHUP 2)SIGINT 3)SIGQUIT 4)SIGILL  5)SIGTRAP 6)SIGABRT 7)SIGEMT 8)SIGFPE  9)SIGKILL 10)SIGBUS 11)SIGSEGV 12)SIGSYS 13)SIGPIPE 14)SIGALRM 15)SIGTERM 16)SIGURG 17)SIGSTOP 18)SIGTSTP 19)SIGCONT 20)SIGCHLD 21)SIGTTIN 22)SIGTTOU 23)SIGIO 24)SIGXCPU 25)SIGXFSZ 26)SIGVTALRM 27)SIGPROF 28)SIGWINCH 29)SIGINFO 30)SIGUSR1 31)SIGUSR2

在我的系统中,“陷阱-l”显示了对信号的选择

daiwang2 回答:python模块'信号'没有属性'SIGHUP'和其他信号

基于documentation,我想您的设备未在SIGHUP内定义signal.h,或者您的python解释器是在不完全相等的设备上构建的给你的。如果确定已定义SIGHUP,则最好是自己重新安装甚至编译python。

,

我在 SIGHUP 用法之前使用此代码使其在 Windows 上工作,可能也适用于 OS X,但我没有办法测试它:

import platform
if platform.system() != 'Linux':
    signal.SIGHUP = 1

之后是 SIGHUP 用法,由于 1 是 Linux 上的初始值,它会像预期的那样工作。

由于 Python 3.7 信号.SIGHUP 仅适用于 Unix 系统,因此不包括 Windows...

我使用了 platform.system() != 'Linux,因为我的脚本只能在 Windows 和 Linux 上运行,但您可以根据自己的需要进行调整。

平台文档:https://docs.python.org/3/library/platform.html#platform.system

信号文档:enter link description here

Linux 上的signal.SIGHUP 值

>>> import signal
>>> signal.SIGHUP
1
本文链接:https://www.f2er.com/3129792.html

大家都在问