diff options
author | Guido van Rossum <guido@python.org> | 2014-11-14 19:48:37 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2014-11-14 19:48:37 (GMT) |
commit | 59f0682190ba80d8796d92943c43810c120ba72d (patch) | |
tree | b78b55216c1789e6b6b04bce821978a1cd60aae3 | |
parent | 6fd113c26cafb321ca65af7d5847bd21dd6324b7 (diff) | |
parent | e36fcde38309f116c6c06042ad80e7debb7db743 (diff) | |
download | cpython-59f0682190ba80d8796d92943c43810c120ba72d.zip cpython-59f0682190ba80d8796d92943c43810c120ba72d.tar.gz cpython-59f0682190ba80d8796d92943c43810c120ba72d.tar.bz2 |
- Issue #22841: Reject coroutines in asyncio add_signal_handler().
Patch by Ludovic.Gasc.
-rw-r--r-- | Lib/asyncio/unix_events.py | 3 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_unix_events.py | 12 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 18 insertions, 0 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index b16f946..e49212e 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -13,6 +13,7 @@ import threading from . import base_events from . import base_subprocess from . import constants +from . import coroutines from . import events from . import selector_events from . import selectors @@ -66,6 +67,8 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): Raise ValueError if the signal number is invalid or uncatchable. Raise RuntimeError if there is a problem setting up the handler. """ + if coroutines.iscoroutinefunction(callback): + raise TypeError("coroutines cannot be used with call_soon()") self._check_signal(sig) try: # set_wakeup_fd() raises ValueError if this is not the diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py index e397598..2f3fa18 100644 --- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -64,6 +64,18 @@ class SelectorEventLoopSignalTests(test_utils.TestCase): signal.SIGINT, lambda: True) @mock.patch('asyncio.unix_events.signal') + def test_add_signal_handler_coroutine_error(self, m_signal): + + @asyncio.coroutine + def simple_coroutine(): + yield from [] + + self.assertRaises( + TypeError, + self.loop.add_signal_handler, + signal.SIGINT, simple_coroutine) + + @mock.patch('asyncio.unix_events.signal') def test_add_signal_handler(self, m_signal): m_signal.NSIG = signal.NSIG @@ -183,6 +183,9 @@ Core and Builtins Library ------- +- Issue #22841: Reject coroutines in asyncio add_signal_handler(). + Patch by Ludovic.Gasc. + - Issue #19494: Added urllib.request.HTTPBasicPriorAuthHandler. Patch by Matej Cepl. |