mirror of https://github.com/python/cpython
Merge 3.4 (asyncio)
This commit is contained in:
commit
42830578c6
|
@ -420,7 +420,7 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
current = events.get_event_loop()
|
current = events.get_event_loop()
|
||||||
except AssertionError:
|
except RuntimeError:
|
||||||
return
|
return
|
||||||
if current is not self:
|
if current is not self:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|
|
@ -517,9 +517,9 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
|
||||||
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.set_event_loop(self.new_event_loop())
|
self.set_event_loop(self.new_event_loop())
|
||||||
assert self._local._loop is not None, \
|
if self._local._loop is None:
|
||||||
('There is no current event loop in thread %r.' %
|
raise RuntimeError('There is no current event loop in thread %r.'
|
||||||
threading.current_thread().name)
|
% threading.current_thread().name)
|
||||||
return self._local._loop
|
return self._local._loop
|
||||||
|
|
||||||
def set_event_loop(self, loop):
|
def set_event_loop(self, loop):
|
||||||
|
|
|
@ -2252,14 +2252,14 @@ class PolicyTests(unittest.TestCase):
|
||||||
def test_get_event_loop_after_set_none(self):
|
def test_get_event_loop_after_set_none(self):
|
||||||
policy = asyncio.DefaultEventLoopPolicy()
|
policy = asyncio.DefaultEventLoopPolicy()
|
||||||
policy.set_event_loop(None)
|
policy.set_event_loop(None)
|
||||||
self.assertRaises(AssertionError, policy.get_event_loop)
|
self.assertRaises(RuntimeError, policy.get_event_loop)
|
||||||
|
|
||||||
@mock.patch('asyncio.events.threading.current_thread')
|
@mock.patch('asyncio.events.threading.current_thread')
|
||||||
def test_get_event_loop_thread(self, m_current_thread):
|
def test_get_event_loop_thread(self, m_current_thread):
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
policy = asyncio.DefaultEventLoopPolicy()
|
policy = asyncio.DefaultEventLoopPolicy()
|
||||||
self.assertRaises(AssertionError, policy.get_event_loop)
|
self.assertRaises(RuntimeError, policy.get_event_loop)
|
||||||
|
|
||||||
th = threading.Thread(target=f)
|
th = threading.Thread(target=f)
|
||||||
th.start()
|
th.start()
|
||||||
|
|
Loading…
Reference in New Issue