Skip to content

minor mismatch in add_signal_handler #12

Description

@claws

I picked this up in my unit tests which are admittedly testing some edge cases. When trying to use the loop to register a signal handler for SIGKILL (which itself is invalid) asyncio and uvloop behave differently.

A simple test that demonstrates the difference is this:

import asyncio
import signal

# import uvloop
# asyncio.DefaultEventLoopPolicy = uvloop.EventLoopPolicy
# asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

def my_sig_handler():
    pass

loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGKILL, my_sig_handler)
loop.stop()
loop.close()

Running the script as is produces the asyncio output:

$ python3.5 uvloop-sig-test.py 
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/asyncio/unix_events.py", line 95, in add_signal_handler
    signal.signal(sig, _sighandler_noop)
  File "/usr/local/lib/python3.5/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "uvloop-sig-test.py", line 31, in <module>
    loop.add_signal_handler(signal.SIGKILL, my_sig_handler)
  File "/usr/local/lib/python3.5/asyncio/unix_events.py", line 108, in add_signal_handler
    raise RuntimeError('sig {} cannot be caught'.format(sig))
RuntimeError: sig 9 cannot be caught

By uncommenting the uvloop part and running the script will produce the uvloop output:

$ python3.5 uvloop-sig-test.py 
Traceback (most recent call last):
  File "uvloop-sig-test.py", line 31, in <module>
    loop.add_signal_handler(signal.SIGKILL, my_sig_handler)
  File "uvloop/loop.pyx", line 1632, in uvloop.loop.Loop.add_signal_handler (uvloop/loop.c:30442)
  File "uvloop/handles/signal.pyx", line 52, in uvloop.loop.UVSignal.start (uvloop/loop.c:42667)
  File "uvloop/handles/handle.pyx", line 145, in uvloop.loop.UVHandle._fatal_error (uvloop/loop.c:37619)
OSError: [Errno 22] Invalid argument

On the box that I ran this test on the Python version was 3.5.0 (not the latest 3.5.1) so the Python module line numbers may be a little out.

I actually think that uvloop does the right thing in reporting the first error. However it would appear that the asyncio developers observed that the error reported is not very informative and wrapped it with a more informative error report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions