Kaydet (Commit) cced0762 authored tarafından Guido van Rossum's avatar Guido van Rossum

asyncio: Fix get_event_loop() to call set_event_loop() when setting the loop. By Anthony Baire.

üst 1314ef73
...@@ -360,7 +360,7 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy): ...@@ -360,7 +360,7 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
if (self._local._loop is None and if (self._local._loop is None and
not self._local._set_called and not self._local._set_called and
isinstance(threading.current_thread(), threading._MainThread)): 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, \ assert self._local._loop is not None, \
('There is no current event loop in thread %r.' % ('There is no current event loop in thread %r.' %
threading.current_thread().name) threading.current_thread().name)
......
...@@ -1599,6 +1599,22 @@ class PolicyTests(unittest.TestCase): ...@@ -1599,6 +1599,22 @@ class PolicyTests(unittest.TestCase):
self.assertIs(loop, policy.get_event_loop()) self.assertIs(loop, policy.get_event_loop())
loop.close() 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): def test_get_event_loop_after_set_none(self):
policy = self.create_policy() policy = self.create_policy()
policy.set_event_loop(None) policy.set_event_loop(None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment