mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +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):
|
||||
"""Run until stop() is called."""
|
||||
self._run_forever_setup()
|
||||
try:
|
||||
self._run_forever_setup()
|
||||
while True:
|
||||
self._run_once()
|
||||
if self._stopping:
|
||||
|
|
|
@ -3004,6 +3004,22 @@ class GetEventLoopTestsMixin:
|
|||
self.loop.run_until_complete(main()),
|
||||
'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):
|
||||
class TestError(Exception):
|
||||
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