gh-130145: fix loop.run_forever when loop is already running (#130146)

This commit is contained in:
Kumar Aditya 2025-02-15 15:01:53 +05:30 committed by GitHub
parent a05433f24a
commit a545749b0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View file

@ -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