Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e36fcde

Browse files
committed
- Issue #22841: Reject coroutines in asyncio add_signal_handler().
Patch by Ludovic.Gasc.
1 parent 6c14f23 commit e36fcde

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/asyncio/unix_events.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from . import base_events
1414
from . import base_subprocess
1515
from . import constants
16+
from . import coroutines
1617
from . import events
1718
from . import selector_events
1819
from . import selectors
@@ -66,6 +67,8 @@ def add_signal_handler(self, sig, callback, *args):
6667
Raise ValueError if the signal number is invalid or uncatchable.
6768
Raise RuntimeError if there is a problem setting up the handler.
6869
"""
70+
if coroutines.iscoroutinefunction(callback):
71+
raise TypeError("coroutines cannot be used with call_soon()")
6972
self._check_signal(sig)
7073
try:
7174
# set_wakeup_fd() raises ValueError if this is not the

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ def test_add_signal_handler_setup_error(self, m_signal):
6363
self.loop.add_signal_handler,
6464
signal.SIGINT, lambda: True)
6565

66+
@mock.patch('asyncio.unix_events.signal')
67+
def test_add_signal_handler_coroutine_error(self, m_signal):
68+
69+
@asyncio.coroutine
70+
def simple_coroutine():
71+
yield from []
72+
73+
self.assertRaises(
74+
TypeError,
75+
self.loop.add_signal_handler,
76+
signal.SIGINT, simple_coroutine)
77+
6678
@mock.patch('asyncio.unix_events.signal')
6779
def test_add_signal_handler(self, m_signal):
6880
m_signal.NSIG = signal.NSIG

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Core and Builtins
3636
Library
3737
-------
3838

39+
- Issue #22841: Reject coroutines in asyncio add_signal_handler().
40+
Patch by Ludovic.Gasc.
41+
3942
- Issue #22849: Fix possible double free in the io.TextIOWrapper constructor.
4043

4144
- Issue #12728: Different Unicode characters having the same uppercase but

0 commit comments

Comments
 (0)