]> granicus.if.org Git - python/commitdiff
asyncio: Fix get_event_loop() to call set_event_loop() when setting the loop. By...
authorGuido van Rossum <guido@python.org>
Wed, 27 Nov 2013 18:37:13 +0000 (10:37 -0800)
committerGuido van Rossum <guido@python.org>
Wed, 27 Nov 2013 18:37:13 +0000 (10:37 -0800)
Lib/asyncio/events.py
Lib/test/test_asyncio/test_events.py

index 36ae312b079eeb47562047d46e946d760b2f9be3..d429686b18a2d26a8aa1c996302619dece417e8f 100644 (file)
@@ -360,7 +360,7 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
         if (self._local._loop is None and
             not self._local._set_called and
             isinstance(threading.current_thread(), threading._MainThread)):
-            self._local._loop = self.new_event_loop()
+            self.set_event_loop(self.new_event_loop())
         assert self._local._loop is not None, \
                ('There is no current event loop in thread %r.' %
                 threading.current_thread().name)
index 6abc72435af55eddc5034a2e5b9bb45a1d11e573..18411ecc246b1ab71723a00347df12b0eb8217e2 100644 (file)
@@ -1599,6 +1599,22 @@ class PolicyTests(unittest.TestCase):
         self.assertIs(loop, policy.get_event_loop())
         loop.close()
 
+    def test_get_event_loop_calls_set_event_loop(self):
+        policy = self.create_policy()
+
+        with unittest.mock.patch.object(
+                policy, "set_event_loop",
+                wraps=policy.set_event_loop) as m_set_event_loop:
+
+            loop = policy.get_event_loop()
+
+            # policy._local._loop must be set through .set_event_loop()
+            # (the unix DefaultEventLoopPolicy needs this call to attach
+            # the child watcher correctly)
+            m_set_event_loop.assert_called_with(loop)
+
+        loop.close()
+
     def test_get_event_loop_after_set_none(self):
         policy = self.create_policy()
         policy.set_event_loop(None)