summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-12-18 00:20:10 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-12-18 00:20:10 (GMT)
commit3a1c738e6cf09d0972809fa431bf77dd564ff713 (patch)
tree85835dd31020158df43ad2830ecabf345b25a27c
parent2338156fa4f8d6c04601f9972c36a7b06bd685bc (diff)
downloadcpython-3a1c738e6cf09d0972809fa431bf77dd564ff713.zip
cpython-3a1c738e6cf09d0972809fa431bf77dd564ff713.tar.gz
cpython-3a1c738e6cf09d0972809fa431bf77dd564ff713.tar.bz2
Issue #23074: asyncio.get_event_loop() now raises an exception if the thread
has no event loop even if assertions are disabled.
-rw-r--r--Lib/asyncio/base_events.py2
-rw-r--r--Lib/asyncio/events.py6
-rw-r--r--Lib/test/test_asyncio/test_events.py4
3 files changed, 6 insertions, 6 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 0c7316e..b1a5422 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -420,7 +420,7 @@ class BaseEventLoop(events.AbstractEventLoop):
"""
try:
current = events.get_event_loop()
- except AssertionError:
+ except RuntimeError:
return
if current is not self:
raise RuntimeError(
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 806218f..8a7bb81 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -517,9 +517,9 @@ class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
not self._local._set_called and
isinstance(threading.current_thread(), threading._MainThread)):
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)
+ if self._local._loop is None:
+ raise RuntimeError('There is no current event loop in thread %r.'
+ % threading.current_thread().name)
return self._local._loop
def set_event_loop(self, loop):
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 6644fbe..d7e2f34 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2252,14 +2252,14 @@ class PolicyTests(unittest.TestCase):
def test_get_event_loop_after_set_none(self):
policy = asyncio.DefaultEventLoopPolicy()
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')
def test_get_event_loop_thread(self, m_current_thread):
def f():
policy = asyncio.DefaultEventLoopPolicy()
- self.assertRaises(AssertionError, policy.get_event_loop)
+ self.assertRaises(RuntimeError, policy.get_event_loop)
th = threading.Thread(target=f)
th.start()