mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
468c3bf798
commit
e5bd5ad70d
8 changed files with 77 additions and 41 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue