mirror of
https://github.com/python/cpython.git
synced 2025-10-15 11:22:18 +00:00
gh-130145: fix loop.run_forever
when loop is already running (#130146)
This commit is contained in:
parent
a05433f24a
commit
a545749b0e
3 changed files with 18 additions and 1 deletions
|
@ -671,8 +671,8 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
|
|
||||||
def run_forever(self):
|
def run_forever(self):
|
||||||
"""Run until stop() is called."""
|
"""Run until stop() is called."""
|
||||||
try:
|
|
||||||
self._run_forever_setup()
|
self._run_forever_setup()
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
self._run_once()
|
self._run_once()
|
||||||
if self._stopping:
|
if self._stopping:
|
||||||
|
|
|
@ -3004,6 +3004,22 @@ class GetEventLoopTestsMixin:
|
||||||
self.loop.run_until_complete(main()),
|
self.loop.run_until_complete(main()),
|
||||||
'hello')
|
'hello')
|
||||||
|
|
||||||
|
def test_get_running_loop_already_running(self):
|
||||||
|
async def main():
|
||||||
|
running_loop = asyncio.get_running_loop()
|
||||||
|
loop = asyncio.new_event_loop()
|
||||||
|
try:
|
||||||
|
loop.run_forever()
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self.fail("RuntimeError not raised")
|
||||||
|
|
||||||
|
self.assertIs(asyncio.get_running_loop(), running_loop)
|
||||||
|
|
||||||
|
self.loop.run_until_complete(main())
|
||||||
|
|
||||||
|
|
||||||
def test_get_event_loop_returns_running_loop(self):
|
def test_get_event_loop_returns_running_loop(self):
|
||||||
class TestError(Exception):
|
class TestError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix :meth:`!asyncio.AbstractEventloop.run_forever` when another loop is already running.
|
Loading…
Add table
Add a link
Reference in a new issue