[Python-checkins] cpython: asyncio: Add close() back to Unix selector event loop, to remove all signal

guido.van.rossum python-checkins at python.org
Thu Nov 7 05:25:56 CET 2013


http://hg.python.org/cpython/rev/89873f3b18fd
changeset:   86983:89873f3b18fd
user:        Guido van Rossum <guido at dropbox.com>
date:        Wed Nov 06 20:25:50 2013 -0800
summary:
  asyncio: Add close() back to Unix selector event loop, to remove all signal handlers. Should fix buildbot issues.

files:
  Lib/asyncio/unix_events.py                |   5 +++
  Lib/test/test_asyncio/test_unix_events.py |  16 +++++++++++
  2 files changed, 21 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
@@ -48,6 +48,11 @@
     def _socketpair(self):
         return socket.socketpair()
 
+    def close(self):
+        for sig in list(self._signal_handlers):
+            self.remove_signal_handler(sig)
+        super().close()
+
     def add_signal_handler(self, sig, callback, *args):
         """Add a handler for a signal.  UNIX only.
 
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
@@ -183,6 +183,22 @@
         self.assertRaises(
             RuntimeError, self.loop.remove_signal_handler, signal.SIGHUP)
 
+    @unittest.mock.patch('asyncio.unix_events.signal')
+    def test_close(self, m_signal):
+        m_signal.NSIG = signal.NSIG
+
+        self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
+        self.loop.add_signal_handler(signal.SIGCHLD, lambda: True)
+
+        self.assertEqual(len(self.loop._signal_handlers), 2)
+
+        m_signal.set_wakeup_fd.reset_mock()
+
+        self.loop.close()
+
+        self.assertEqual(len(self.loop._signal_handlers), 0)
+        m_signal.set_wakeup_fd.assert_called_once_with(-1)
+
 
 class UnixReadPipeTransportTests(unittest.TestCase):
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list