Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs
  • Loading branch information
kumaraditya303 committed Apr 10, 2025
commit d96ea053d90d2808b679bb52927c8e224aa06ff8
1 change: 0 additions & 1 deletion Doc/deprecations/pending-removal-in-3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Pending removal in Python 3.16
* :class:`asyncio.WindowsProactorEventLoopPolicy`
* :func:`asyncio.get_event_loop_policy`
* :func:`asyncio.set_event_loop_policy`
* :func:`asyncio.set_event_loop`

Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
*loop_factory* to use the desired event loop implementation.
Expand Down
10 changes: 3 additions & 7 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,14 @@ an event loop:
.. note::

The :mod:`!asyncio` policy system is deprecated and will be removed
in Python 3.16; from there on, this function will always return the
running event loop.

in Python 3.16; from there on, this function will return the current
running event loop if present else it will return the
loop set by :func:`set_event_loop`.

.. function:: set_event_loop(loop)

Set *loop* as the current event loop for the current OS thread.

.. deprecated:: 3.14
The :func:`set_event_loop` function is deprecated and will be removed
in Python 3.16.

.. function:: new_event_loop()

Create and return a new event loop object.
Expand Down
2 changes: 1 addition & 1 deletion Lib/asyncio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"_set_event_loop_policy",
"set_event_loop_policy",
"get_event_loop",
"_set_event_loop",
"set_event_loop",
"set_event_loop",
"new_event_loop",
"_set_running_loop",
Expand Down
4 changes: 2 additions & 2 deletions Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def close(self):
loop.shutdown_default_executor(constants.THREAD_JOIN_TIMEOUT))
finally:
if self._set_event_loop:
events._set_event_loop(None)
events.set_event_loop(None)
loop.close()
self._loop = None
self._state = _State.CLOSED
Expand Down Expand Up @@ -147,7 +147,7 @@ def _lazy_init(self):
if not self._set_event_loop:
# Call set_event_loop only once to avoid calling
# attach_loop multiple times on child watchers
events._set_event_loop(self._loop)
events.set_event_loop(self._loop)
self._set_event_loop = True
else:
self._loop = self._loop_factory()
Expand Down
8 changes: 0 additions & 8 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2830,14 +2830,6 @@ async def inner():

class PolicyTests(unittest.TestCase):

def test_asyncio_set_event_loop_deprecation(self):
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.set_event_loop' is deprecated"):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
self.assertIs(loop, asyncio.get_event_loop())
loop.close()

def test_abstract_event_loop_policy_deprecation(self):
with self.assertWarnsRegex(
DeprecationWarning, "'asyncio.AbstractEventLoopPolicy' is deprecated"):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def test():
def test_constructor_use_global_loop(self):
# Deprecated in 3.10, undeprecated in 3.12
asyncio.set_event_loop(self.loop)
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
f = self._new_future()
self.assertIs(f._loop, self.loop)
self.assertIs(f.get_loop(), self.loop)
Expand Down Expand Up @@ -567,7 +567,7 @@ async def test():
def test_wrap_future_use_global_loop(self):
# Deprecated in 3.10, undeprecated in 3.12
asyncio.set_event_loop(self.loop)
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
def run(arg):
return (arg, threading.get_ident())
ex = concurrent.futures.ThreadPoolExecutor(1)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def test_streamreader_constructor_use_global_loop(self):
# asyncio issue #184: Ensure that StreamReaderProtocol constructor
# retrieves the current loop if the loop parameter is not set
# Deprecated in 3.10, undeprecated in 3.12
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
asyncio.set_event_loop(self.loop)
reader = asyncio.StreamReader()
self.assertIs(reader._loop, self.loop)
Expand All @@ -860,7 +860,7 @@ def test_streamreaderprotocol_constructor_use_global_loop(self):
# asyncio issue #184: Ensure that StreamReaderProtocol constructor
# retrieves the current loop if the loop parameter is not set
# Deprecated in 3.10, undeprecated in 3.12
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
asyncio.set_event_loop(self.loop)
reader = mock.Mock()
protocol = asyncio.StreamReaderProtocol(reader)
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def test():

# Deprecated in 3.10, undeprecated in 3.12
asyncio.set_event_loop(self.loop)
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
t = asyncio.ensure_future(notmuch())
self.assertIs(t._loop, self.loop)
self.loop.run_until_complete(t)
Expand Down Expand Up @@ -2203,7 +2203,7 @@ async def coro():
return 42

asyncio.set_event_loop(self.loop)
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
outer = asyncio.shield(coro())
self.assertEqual(outer._loop, self.loop)
res = self.loop.run_until_complete(outer)
Expand Down Expand Up @@ -3323,7 +3323,7 @@ async def gather():
def test_constructor_empty_sequence_use_global_loop(self):
# Deprecated in 3.10, undeprecated in 3.12
asyncio.set_event_loop(self.one_loop)
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
fut = asyncio.gather()
self.assertIsInstance(fut, asyncio.Future)
self.assertIs(fut._loop, self.one_loop)
Expand Down Expand Up @@ -3431,7 +3431,7 @@ def test_constructor_use_global_loop(self):
async def coro():
return 'abc'
asyncio.set_event_loop(self.other_loop)
self.addCleanup(asyncio._set_event_loop, None)
self.addCleanup(asyncio.set_event_loop, None)
gen1 = coro()
gen2 = coro()
fut = asyncio.gather(gen1, gen2)
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def set_event_loop(self, loop, *, cleanup=True):
if loop is None:
raise AssertionError('loop is None')
# ensure that the event loop is passed explicitly in asyncio
events._set_event_loop(None)
events.set_event_loop(None)
if cleanup:
self.addCleanup(self.close_loop, loop)

Expand All @@ -553,7 +553,7 @@ def setUp(self):
self._thread_cleanup = threading_helper.threading_setup()

def tearDown(self):
events._set_event_loop(None)
events.set_event_loop(None)

# Detect CPython bug #23353: ensure that yield/yield-from is not used
# in an except block of a generator
Expand Down
Loading