Skip to content

Commit a488879

Browse files
authored
bpo-36373: Deprecate explicit loop in task and subprocess API (GH-16033)
1 parent 3ab6147 commit a488879

File tree

7 files changed

+178
-101
lines changed

7 files changed

+178
-101
lines changed

Doc/library/asyncio-subprocess.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Creating Subprocesses
7171
See the documentation of :meth:`loop.subprocess_exec` for other
7272
parameters.
7373

74+
.. deprecated-removed:: 3.8 3.10
75+
76+
The *loop* parameter.
77+
7478
.. coroutinefunction:: create_subprocess_shell(cmd, stdin=None, \
7579
stdout=None, stderr=None, loop=None, \
7680
limit=None, \*\*kwds)
@@ -95,6 +99,10 @@ Creating Subprocesses
9599
escape whitespace and special shell characters in strings that are going
96100
to be used to construct shell commands.
97101

102+
.. deprecated-removed:: 3.8 3.10
103+
104+
The *loop* parameter.
105+
98106
.. note::
99107

100108
The default asyncio event loop implementation on **Windows** does not

Doc/library/asyncio-task.rst

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ Running Tasks Concurrently
334334
cancellation of one submitted Task/Future to cause other
335335
Tasks/Futures to be cancelled.
336336

337+
.. deprecated-removed:: 3.8 3.10
338+
The *loop* parameter.
339+
337340
.. _asyncio_example_gather:
338341

339342
Example::
@@ -411,6 +414,9 @@ Shielding From Cancellation
411414
except CancelledError:
412415
res = None
413416

417+
.. deprecated-removed:: 3.8 3.10
418+
The *loop* parameter.
419+
414420

415421
Timeouts
416422
========
@@ -478,22 +484,12 @@ Waiting Primitives
478484
set concurrently and block until the condition specified
479485
by *return_when*.
480486

481-
.. deprecated:: 3.8
482-
483-
If any awaitable in *aws* is a coroutine, it is automatically
484-
scheduled as a Task. Passing coroutines objects to
485-
``wait()`` directly is deprecated as it leads to
486-
:ref:`confusing behavior <asyncio_example_wait_coroutine>`.
487-
488487
Returns two sets of Tasks/Futures: ``(done, pending)``.
489488

490489
Usage::
491490

492491
done, pending = await asyncio.wait(aws)
493492

494-
.. deprecated-removed:: 3.8 3.10
495-
The *loop* parameter.
496-
497493
*timeout* (a float or int), if specified, can be used to control
498494
the maximum number of seconds to wait before returning.
499495

@@ -525,6 +521,17 @@ Waiting Primitives
525521
Unlike :func:`~asyncio.wait_for`, ``wait()`` does not cancel the
526522
futures when a timeout occurs.
527523

524+
.. deprecated:: 3.8
525+
526+
If any awaitable in *aws* is a coroutine, it is automatically
527+
scheduled as a Task. Passing coroutines objects to
528+
``wait()`` directly is deprecated as it leads to
529+
:ref:`confusing behavior <asyncio_example_wait_coroutine>`.
530+
531+
.. deprecated-removed:: 3.8 3.10
532+
533+
The *loop* parameter.
534+
528535
.. _asyncio_example_wait_coroutine:
529536
.. note::
530537

@@ -568,6 +575,9 @@ Waiting Primitives
568575
Raises :exc:`asyncio.TimeoutError` if the timeout occurs before
569576
all Futures are done.
570577

578+
.. deprecated-removed:: 3.8 3.10
579+
The *loop* parameter.
580+
571581
Example::
572582

573583
for f in as_completed(aws):
@@ -694,6 +704,9 @@ Task Object
694704
.. versionchanged:: 3.8
695705
Added the ``name`` parameter.
696706

707+
.. deprecated-removed:: 3.8 3.10
708+
The *loop* parameter.
709+
697710
.. method:: cancel()
698711

699712
Request the Task to be cancelled.

Lib/asyncio/subprocess.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ async def create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None,
224224
**kwds):
225225
if loop is None:
226226
loop = events.get_event_loop()
227+
else:
228+
warnings.warn("The loop argument is deprecated since Python 3.8 "
229+
"and scheduled for removal in Python 3.10.",
230+
DeprecationWarning,
231+
stacklevel=2
232+
)
233+
227234
protocol_factory = lambda: SubprocessStreamProtocol(limit=limit,
228235
loop=loop,
229236
_asyncio_internal=True)
@@ -239,6 +246,12 @@ async def create_subprocess_exec(program, *args, stdin=None, stdout=None,
239246
limit=streams._DEFAULT_LIMIT, **kwds):
240247
if loop is None:
241248
loop = events.get_event_loop()
249+
else:
250+
warnings.warn("The loop argument is deprecated since Python 3.8 "
251+
"and scheduled for removal in Python 3.10.",
252+
DeprecationWarning,
253+
stacklevel=2
254+
)
242255
protocol_factory = lambda: SubprocessStreamProtocol(limit=limit,
243256
loop=loop,
244257
_asyncio_internal=True)

Lib/asyncio/tasks.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,17 @@ def as_completed(fs, *, loop=None, timeout=None):
573573
"""
574574
if futures.isfuture(fs) or coroutines.iscoroutine(fs):
575575
raise TypeError(f"expect a list of futures, not {type(fs).__name__}")
576-
loop = loop if loop is not None else events.get_event_loop()
577-
todo = {ensure_future(f, loop=loop) for f in set(fs)}
576+
578577
from .queues import Queue # Import here to avoid circular import problem.
579578
done = Queue(loop=loop)
579+
580+
if loop is None:
581+
loop = events.get_event_loop()
582+
else:
583+
warnings.warn("The loop argument is deprecated since Python 3.8, "
584+
"and scheduled for removal in Python 3.10.",
585+
DeprecationWarning, stacklevel=2)
586+
todo = {ensure_future(f, loop=loop) for f in set(fs)}
580587
timeout_handle = None
581588

582589
def _on_timeout():
@@ -733,6 +740,10 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
733740
if not coros_or_futures:
734741
if loop is None:
735742
loop = events.get_event_loop()
743+
else:
744+
warnings.warn("The loop argument is deprecated since Python 3.8, "
745+
"and scheduled for removal in Python 3.10.",
746+
DeprecationWarning, stacklevel=2)
736747
outer = loop.create_future()
737748
outer.set_result([])
738749
return outer
@@ -842,6 +853,10 @@ def shield(arg, *, loop=None):
842853
except CancelledError:
843854
res = None
844855
"""
856+
if loop is not None:
857+
warnings.warn("The loop argument is deprecated since Python 3.8, "
858+
"and scheduled for removal in Python 3.10.",
859+
DeprecationWarning, stacklevel=2)
845860
inner = ensure_future(arg, loop=loop)
846861
if inner.done():
847862
# Shortcut.

Lib/test/test_asyncio/test_streams.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,10 @@ def test_read_all_from_pipe_reader(self):
855855
watcher.attach_loop(self.loop)
856856
try:
857857
asyncio.set_child_watcher(watcher)
858-
create = asyncio.create_subprocess_exec(*args,
859-
pass_fds={wfd},
860-
loop=self.loop)
858+
create = asyncio.create_subprocess_exec(
859+
*args,
860+
pass_fds={wfd},
861+
)
861862
proc = self.loop.run_until_complete(create)
862863
self.loop.run_until_complete(proc.wait())
863864
finally:

0 commit comments

Comments
 (0)