Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a488879c
Commit
a488879c
authored
Sep 12, 2019
by
Andrew Svetlov
Committed by
GitHub
Sep 12, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-36373: Deprecate explicit loop in task and subprocess API (GH-16033)
parent
3ab61473
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
178 additions
and
101 deletions
+178
-101
Doc/library/asyncio-subprocess.rst
Doc/library/asyncio-subprocess.rst
+8
-0
Doc/library/asyncio-task.rst
Doc/library/asyncio-task.rst
+23
-10
Lib/asyncio/subprocess.py
Lib/asyncio/subprocess.py
+13
-0
Lib/asyncio/tasks.py
Lib/asyncio/tasks.py
+17
-2
Lib/test/test_asyncio/test_streams.py
Lib/test/test_asyncio/test_streams.py
+4
-3
Lib/test/test_asyncio/test_subprocess.py
Lib/test/test_asyncio/test_subprocess.py
+105
-79
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+8
-7
No files found.
Doc/library/asyncio-subprocess.rst
View file @
a488879c
...
...
@@ -71,6 +71,10 @@ Creating Subprocesses
See the documentation of :meth:`loop.subprocess_exec` for other
parameters.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
.. coroutinefunction:: create_subprocess_shell(cmd, stdin=None, \
stdout=None, stderr=None, loop=None, \
limit=None, \*\*kwds)
...
...
@@ -95,6 +99,10 @@ Creating Subprocesses
escape whitespace and special shell characters in strings that are going
to be used to construct shell commands.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
.. note::
The default asyncio event loop implementation on **Windows** does not
...
...
Doc/library/asyncio-task.rst
View file @
a488879c
...
...
@@ -334,6 +334,9 @@ Running Tasks Concurrently
cancellation of one submitted Task/Future to cause other
Tasks/Futures to be cancelled.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
.. _asyncio_example_gather:
Example::
...
...
@@ -411,6 +414,9 @@ Shielding From Cancellation
except CancelledError:
res = None
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
Timeouts
========
...
...
@@ -478,22 +484,12 @@ Waiting Primitives
set concurrently and block until the condition specified
by *return_when*.
.. deprecated:: 3.8
If any awaitable in *aws* is a coroutine, it is automatically
scheduled as a Task. Passing coroutines objects to
``wait()`` directly is deprecated as it leads to
:ref:`confusing behavior <asyncio_example_wait_coroutine>`.
Returns two sets of Tasks/Futures: ``(done, pending)``.
Usage::
done, pending = await asyncio.wait(aws)
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
*timeout* (a float or int), if specified, can be used to control
the maximum number of seconds to wait before returning.
...
...
@@ -525,6 +521,17 @@ Waiting Primitives
Unlike :func:`~asyncio.wait_for`, ``wait()`` does not cancel the
futures when a timeout occurs.
.. deprecated:: 3.8
If any awaitable in *aws* is a coroutine, it is automatically
scheduled as a Task. Passing coroutines objects to
``wait()`` directly is deprecated as it leads to
:ref:`confusing behavior <asyncio_example_wait_coroutine>`.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
.. _asyncio_example_wait_coroutine:
.. note::
...
...
@@ -568,6 +575,9 @@ Waiting Primitives
Raises :exc:`asyncio.TimeoutError` if the timeout occurs before
all Futures are done.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
Example::
for f in as_completed(aws):
...
...
@@ -694,6 +704,9 @@ Task Object
.. versionchanged:: 3.8
Added the ``name`` parameter.
.. deprecated-removed:: 3.8 3.10
The *loop* parameter.
.. method:: cancel()
Request the Task to be cancelled.
...
...
Lib/asyncio/subprocess.py
View file @
a488879c
...
...
@@ -224,6 +224,13 @@ async def create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None,
**
kwds
):
if
loop
is
None
:
loop
=
events
.
get_event_loop
()
else
:
warnings
.
warn
(
"The loop argument is deprecated since Python 3.8 "
"and scheduled for removal in Python 3.10."
,
DeprecationWarning
,
stacklevel
=
2
)
protocol_factory
=
lambda
:
SubprocessStreamProtocol
(
limit
=
limit
,
loop
=
loop
,
_asyncio_internal
=
True
)
...
...
@@ -239,6 +246,12 @@ async def create_subprocess_exec(program, *args, stdin=None, stdout=None,
limit
=
streams
.
_DEFAULT_LIMIT
,
**
kwds
):
if
loop
is
None
:
loop
=
events
.
get_event_loop
()
else
:
warnings
.
warn
(
"The loop argument is deprecated since Python 3.8 "
"and scheduled for removal in Python 3.10."
,
DeprecationWarning
,
stacklevel
=
2
)
protocol_factory
=
lambda
:
SubprocessStreamProtocol
(
limit
=
limit
,
loop
=
loop
,
_asyncio_internal
=
True
)
...
...
Lib/asyncio/tasks.py
View file @
a488879c
...
...
@@ -573,10 +573,17 @@ def as_completed(fs, *, loop=None, timeout=None):
"""
if
futures
.
isfuture
(
fs
)
or
coroutines
.
iscoroutine
(
fs
):
raise
TypeError
(
f"expect a list of futures, not
{
type
(
fs
).
__name__
}
"
)
loop
=
loop
if
loop
is
not
None
else
events
.
get_event_loop
()
todo
=
{
ensure_future
(
f
,
loop
=
loop
)
for
f
in
set
(
fs
)}
from
.queues
import
Queue
# Import here to avoid circular import problem.
done
=
Queue
(
loop
=
loop
)
if
loop
is
None
:
loop
=
events
.
get_event_loop
()
else
:
warnings
.
warn
(
"The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10."
,
DeprecationWarning
,
stacklevel
=
2
)
todo
=
{
ensure_future
(
f
,
loop
=
loop
)
for
f
in
set
(
fs
)}
timeout_handle
=
None
def
_on_timeout
():
...
...
@@ -733,6 +740,10 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
if
not
coros_or_futures
:
if
loop
is
None
:
loop
=
events
.
get_event_loop
()
else
:
warnings
.
warn
(
"The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10."
,
DeprecationWarning
,
stacklevel
=
2
)
outer
=
loop
.
create_future
()
outer
.
set_result
([])
return
outer
...
...
@@ -842,6 +853,10 @@ def shield(arg, *, loop=None):
except CancelledError:
res = None
"""
if
loop
is
not
None
:
warnings
.
warn
(
"The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10."
,
DeprecationWarning
,
stacklevel
=
2
)
inner
=
ensure_future
(
arg
,
loop
=
loop
)
if
inner
.
done
():
# Shortcut.
...
...
Lib/test/test_asyncio/test_streams.py
View file @
a488879c
...
...
@@ -855,9 +855,10 @@ os.close(fd)
watcher
.
attach_loop
(
self
.
loop
)
try
:
asyncio
.
set_child_watcher
(
watcher
)
create
=
asyncio
.
create_subprocess_exec
(
*
args
,
pass_fds
=
{
wfd
},
loop
=
self
.
loop
)
create
=
asyncio
.
create_subprocess_exec
(
*
args
,
pass_fds
=
{
wfd
},
)
proc
=
self
.
loop
.
run_until_complete
(
create
)
self
.
loop
.
run_until_complete
(
proc
.
wait
())
finally
:
...
...
Lib/test/test_asyncio/test_subprocess.py
View file @
a488879c
This diff is collapsed.
Click to expand it.
Lib/test/test_asyncio/test_tasks.py
View file @
a488879c
...
...
@@ -1810,7 +1810,7 @@ class BaseTaskTests:
async
def
outer
():
nonlocal
proof
await
asyncio
.
shield
(
inner
()
,
loop
=
self
.
loop
)
await
asyncio
.
shield
(
inner
())
proof
+=
100
f
=
asyncio
.
ensure_future
(
outer
(),
loop
=
self
.
loop
)
...
...
@@ -1825,8 +1825,8 @@ class BaseTaskTests:
def
test_shield_gather
(
self
):
child1
=
self
.
new_future
(
self
.
loop
)
child2
=
self
.
new_future
(
self
.
loop
)
parent
=
asyncio
.
gather
(
child1
,
child2
,
loop
=
self
.
loop
)
outer
=
asyncio
.
shield
(
parent
,
loop
=
self
.
loop
)
parent
=
asyncio
.
gather
(
child1
,
child2
)
outer
=
asyncio
.
shield
(
parent
)
test_utils
.
run_briefly
(
self
.
loop
)
outer
.
cancel
()
test_utils
.
run_briefly
(
self
.
loop
)
...
...
@@ -1839,9 +1839,9 @@ class BaseTaskTests:
def
test_gather_shield
(
self
):
child1
=
self
.
new_future
(
self
.
loop
)
child2
=
self
.
new_future
(
self
.
loop
)
inner1
=
asyncio
.
shield
(
child1
,
loop
=
self
.
loop
)
inner2
=
asyncio
.
shield
(
child2
,
loop
=
self
.
loop
)
parent
=
asyncio
.
gather
(
inner1
,
inner2
,
loop
=
self
.
loop
)
inner1
=
asyncio
.
shield
(
child1
)
inner2
=
asyncio
.
shield
(
child2
)
parent
=
asyncio
.
gather
(
inner1
,
inner2
)
test_utils
.
run_briefly
(
self
.
loop
)
parent
.
cancel
()
# This should cancel inner1 and inner2 but bot child1 and child2.
...
...
@@ -2981,7 +2981,8 @@ class FutureGatherTests(GatherTestsBase, test_utils.TestCase):
self
.
_run_loop
(
self
.
one_loop
)
self
.
assertTrue
(
fut
.
done
())
self
.
assertEqual
(
fut
.
result
(),
[])
fut
=
asyncio
.
gather
(
*
seq_or_iter
,
loop
=
self
.
other_loop
)
with
self
.
assertWarns
(
DeprecationWarning
):
fut
=
asyncio
.
gather
(
*
seq_or_iter
,
loop
=
self
.
other_loop
)
self
.
assertIs
(
fut
.
_loop
,
self
.
other_loop
)
def
test_constructor_empty_sequence
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment