Это мой код:
import signal, os
def handler(signum, frame):
print('Signal handler called with signal', signum)
raise OSError("Couldn't open device!")
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(5)
# This open() may hang indefinitely
fd = os.open('/dev/ttyS0', os.O_RDWR)
signal.alarm(0) # Disable the alarm
ps скопировано из официального документа python: https://docs.python.org/3.6/library/signal.html#signal.signal
Затем возникло исключение, следующеемой след назад:
>>> # Set the signal handler and a 5-second alarm
... signal.signal(signal.SIGALRM, handler)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
AttributeError: module 'signal' has no attribute 'SIGALRM'
Затем я изменил signal.SIGALRM
на постоянное целое число 14
, и произошло другое исключение:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
Я нашел интересную и сбивающую с толку вещь:
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> signal.signal
<module 'signal' from '/home/wtq/signal.py'>
>>> signal.signal.signal.signal
<module 'signal' from '/home/wtq/signal.py'>
>>>
Сколько бы я ни вводил, сколько "сигналов", выход всегда является модулем.