gh-100160: Restore and deprecate implicit creation of an event loop (GH-100410)

Partially revert changes made in GH-93453.

asyncio.DefaultEventLoopPolicy.get_event_loop() now emits a
DeprecationWarning and creates and sets a new event loop instead of
raising a RuntimeError if there is no current event loop set.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
This commit is contained in:
Serhiy Storchaka 2023-01-13 14:40:29 +02:00 committed by GitHub
parent 468c3bf798
commit e5bd5ad70d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 41 deletions

View file

@ -1884,7 +1884,9 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
if pid == 0:
# child
try:
loop = asyncio.get_event_loop_policy().get_event_loop()
with self.assertWarns(DeprecationWarning):
loop = asyncio.get_event_loop_policy().get_event_loop()
os.write(w, b'LOOP:' + str(id(loop)).encode())
except RuntimeError:
os.write(w, b'NO LOOP')
except:
@ -1893,7 +1895,9 @@ class TestFork(unittest.IsolatedAsyncioTestCase):
os._exit(0)
else:
# parent
self.assertEqual(os.read(r, 100), b'NO LOOP')
result = os.read(r, 100)
self.assertEqual(result[:5], b'LOOP:', result)
self.assertNotEqual(int(result[5:]), id(loop))
wait_process(pid, exitcode=0)
@hashlib_helper.requires_hashdigest('md5')