Skip to content

Commit d350f91

Browse files
committed
Fix add_signal_handler to raise the same exc asyncio raises for inv signal
1 parent 25a6bca commit d350f91

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

tests/test_signals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ def handler_hup():
262262

263263
self.loop.run_until_complete(runner())
264264

265+
def test_signals_invalid_signal(self):
266+
with self.assertRaisesRegex(RuntimeError,
267+
'sig {} cannot be caught'.format(
268+
signal.SIGKILL)):
269+
270+
self.loop.add_signal_handler(signal.SIGKILL, lambda *a: None)
271+
272+
def test_signals_coro_callback(self):
273+
async def coro(): pass
274+
with self.assertRaisesRegex(TypeError, 'coroutines cannot be used'):
275+
self.loop.add_signal_handler(signal.SIGHUP, coro)
276+
265277

266278
class Test_UV_Signals(_TestSignal, tb.UVTestCase):
267279
NEW_LOOP = 'uvloop.new_event_loop()'

uvloop/includes/system.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ cdef extern from "errno.h" nogil:
5959
int ENOTSOCK
6060
int EBADF
6161
int ENOSYS
62+
int EINVAL

uvloop/loop.pyx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,14 @@ cdef class Loop:
16571657
# any signals installed by user
16581658
return
16591659

1660-
uvs.start()
1660+
try:
1661+
uvs.start()
1662+
except OSError as exc:
1663+
del self._signal_handlers[sig]
1664+
if exc.errno == errno.EINVAL:
1665+
raise RuntimeError('sig {} cannot be caught'.format(sig))
1666+
else:
1667+
raise
16611668

16621669
def remove_signal_handler(self, sig):
16631670
cdef:

0 commit comments

Comments
 (0)