]> granicus.if.org Git - python/commitdiff
- Issue #22841: Reject coroutines in asyncio add_signal_handler().
authorGuido van Rossum <guido@python.org>
Fri, 14 Nov 2014 19:45:47 +0000 (11:45 -0800)
committerGuido van Rossum <guido@python.org>
Fri, 14 Nov 2014 19:45:47 +0000 (11:45 -0800)
  Patch by Ludovic.Gasc.

Lib/asyncio/unix_events.py
Lib/test/test_asyncio/test_unix_events.py
Misc/NEWS

index b16f946ae4bc84b4b1afcebe8399cf4539fd2850..e49212e5ea08bf51c28186b505b238d4ffd99757 100644 (file)
@@ -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
index e397598222d8867af8d79011206a9af529605075..2f3fa185c958ac3fc1636468d46d13c1dba1f83e 100644 (file)
@@ -63,6 +63,18 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
             self.loop.add_signal_handler,
             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
index bb58965623557f26207f95b86592bbc5d965fc12..6a4b81f54bf645c7891e148ece5143792858a39c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -36,6 +36,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #22841: Reject coroutines in asyncio add_signal_handler().
+  Patch by Ludovic.Gasc.
+
 - Issue #22849: Fix possible double free in the io.TextIOWrapper constructor.
 
 - Issue #12728: Different Unicode characters having the same uppercase but