[Python-checkins] cpython (merge 3.4 -> default): - Issue #22841: Reject coroutines in asyncio add_signal_handler().
guido.van.rossum
python-checkins at python.org
Fri Nov 14 20:49:05 CET 2014
https://hg.python.org/cpython/rev/44e77709daa4
changeset: 93486:44e77709daa4
parent: 93480:19b2c54e5f09
parent: 93485:d244e1770f1b
user: Guido van Rossum <guido at python.org>
date: Fri Nov 14 11:48:37 2014 -0800
summary:
- Issue #22841: Reject coroutines in asyncio add_signal_handler().
Patch by Ludovic.Gasc.
files:
Lib/asyncio/unix_events.py | 3 ++
Lib/test/test_asyncio/test_unix_events.py | 12 +++++++++++
Misc/NEWS | 3 ++
3 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -13,6 +13,7 @@
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 @@
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
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -64,6 +64,18 @@
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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -183,6 +183,9 @@
Library
-------
+- Issue #22841: Reject coroutines in asyncio add_signal_handler().
+ Patch by Ludovic.Gasc.
+
- Issue #19494: Added urllib.request.HTTPBasicPriorAuthHandler. Patch by
Matej Cepl.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list