Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ async def start_serving(self):
self._start_serving()
# Skip one loop iteration so that all 'loop.add_reader'
# go through.
await tasks.sleep(0, loop=self._loop)
await tasks.sleep(0)

async def serve_forever(self):
if self._serving_forever_fut is not None:
Expand Down Expand Up @@ -541,8 +541,7 @@ async def shutdown_asyncgens(self):

results = await tasks.gather(
*[ag.aclose() for ag in closing_agens],
return_exceptions=True,
loop=self)
return_exceptions=True)

for result, agen in zip(results, closing_agens):
if isinstance(result, Exception):
Expand Down Expand Up @@ -1457,7 +1456,7 @@ async def create_server(
fs = [self._create_server_getaddrinfo(host, port, family=family,
flags=flags)
for host in hosts]
infos = await tasks.gather(*fs, loop=self)
infos = await tasks.gather(*fs)
infos = set(itertools.chain.from_iterable(infos))

completed = False
Expand Down Expand Up @@ -1515,7 +1514,7 @@ async def create_server(
server._start_serving()
# Skip one loop iteration so that all 'loop.add_reader'
# go through.
await tasks.sleep(0, loop=self)
await tasks.sleep(0)

if self._debug:
logger.info("%r is serving", server)
Expand Down
3 changes: 1 addition & 2 deletions Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def _cancel_all_tasks(loop):
for task in to_cancel:
task.cancel()

loop.run_until_complete(
tasks.gather(*to_cancel, loop=loop, return_exceptions=True))
loop.run_until_complete(tasks.gather(*to_cancel, return_exceptions=True))

for task in to_cancel:
if task.cancelled():
Expand Down
30 changes: 6 additions & 24 deletions Lib/asyncio/subprocess.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__all__ = 'create_subprocess_exec', 'create_subprocess_shell'

import subprocess
import warnings

from . import events
from . import protocols
Expand Down Expand Up @@ -193,24 +192,14 @@ async def communicate(self, input=None):
stderr = self._read_stream(2)
else:
stderr = self._noop()
stdin, stdout, stderr = await tasks.gather(stdin, stdout, stderr,
loop=self._loop)
stdin, stdout, stderr = await tasks.gather(stdin, stdout, stderr)
await self.wait()
return (stdout, stderr)


async def create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None,
loop=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
)

limit=streams._DEFAULT_LIMIT, **kwds):
loop = events.get_running_loop()
protocol_factory = lambda: SubprocessStreamProtocol(limit=limit,
loop=loop)
transport, protocol = await loop.subprocess_shell(
Expand All @@ -221,16 +210,9 @@ async def create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None,


async def create_subprocess_exec(program, *args, stdin=None, stdout=None,
stderr=None, loop=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
)
stderr=None, limit=streams._DEFAULT_LIMIT,
**kwds):
loop = events.get_running_loop()
protocol_factory = lambda: SubprocessStreamProtocol(limit=limit,
loop=loop)
transport, protocol = await loop.subprocess_exec(
Expand Down
55 changes: 13 additions & 42 deletions Lib/asyncio/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def create_task(coro, *, name=None):
ALL_COMPLETED = concurrent.futures.ALL_COMPLETED


async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
async def wait(fs, *, timeout=None, return_when=ALL_COMPLETED):
"""Wait for the Futures and coroutines given by fs to complete.

The fs iterable must not be empty.
Expand All @@ -393,12 +393,7 @@ async def wait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED):
if return_when not in (FIRST_COMPLETED, FIRST_EXCEPTION, ALL_COMPLETED):
raise ValueError(f'Invalid return_when value: {return_when}')

if loop is None:
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
loop = events.get_running_loop()

fs = set(fs)

Expand All @@ -418,7 +413,7 @@ def _release_waiter(waiter, *args):
waiter.set_result(None)


async def wait_for(fut, timeout, *, loop=None):
async def wait_for(fut, timeout):
"""Wait for the single Future or coroutine to complete, with timeout.

Coroutine will be wrapped in Task.
Expand All @@ -431,12 +426,7 @@ async def wait_for(fut, timeout, *, loop=None):

This function is a coroutine.
"""
if loop is None:
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)
loop = events.get_running_loop()

if timeout is None:
return await fut
Expand Down Expand Up @@ -556,7 +546,7 @@ async def _cancel_and_wait(fut, loop):


# This is *not* a @coroutine! It is just an iterator (yielding Futures).
def as_completed(fs, *, loop=None, timeout=None):
def as_completed(fs, *, timeout=None):
"""Return an iterator whose values are coroutines.

When waiting for the yielded coroutines you'll get the results (or
Expand All @@ -580,12 +570,7 @@ def as_completed(fs, *, loop=None, timeout=None):
from .queues import Queue # Import here to avoid circular import problem.
done = Queue()

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)
loop = events.get_event_loop()
todo = {ensure_future(f, loop=loop) for f in set(fs)}
timeout_handle = None

Expand Down Expand Up @@ -630,19 +615,13 @@ def __sleep0():
yield


async def sleep(delay, result=None, *, loop=None):
async def sleep(delay, result=None):
"""Coroutine that completes after a given time (in seconds)."""
if delay <= 0:
await __sleep0()
return result

if loop is None:
loop = events.get_running_loop()
else:
warnings.warn("The loop argument is deprecated since Python 3.8, "
"and scheduled for removal in Python 3.10.",
DeprecationWarning, stacklevel=2)

loop = events.get_running_loop()
future = loop.create_future()
h = loop.call_later(delay,
futures._set_result_unless_cancelled,
Expand Down Expand Up @@ -717,7 +696,7 @@ def cancel(self, msg=None):
return ret


def gather(*coros_or_futures, loop=None, return_exceptions=False):
def gather(*coros_or_futures, return_exceptions=False):
"""Return a future aggregating results from the given coroutines/futures.

Coroutines will be wrapped in a future and scheduled in the event
Expand Down Expand Up @@ -748,12 +727,7 @@ def gather(*coros_or_futures, loop=None, return_exceptions=False):
gather won't cancel any other awaitables.
"""
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)
loop = events.get_event_loop()
outer = loop.create_future()
outer.set_result([])
return outer
Expand Down Expand Up @@ -817,6 +791,7 @@ def _done_callback(fut):
children = []
nfuts = 0
nfinished = 0
loop = None
for arg in coros_or_futures:
if arg not in arg_to_fut:
fut = ensure_future(arg, loop=loop)
Expand All @@ -843,7 +818,7 @@ def _done_callback(fut):
return outer


def shield(arg, *, loop=None):
def shield(arg):
"""Wait for a future, shielding it from cancellation.

The statement
Expand All @@ -869,11 +844,7 @@ 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)
inner = ensure_future(arg)
if inner.done():
# Shortcut.
return inner
Expand Down
2 changes: 1 addition & 1 deletion Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async def create_unix_server(
server._start_serving()
# Skip one loop iteration so that all 'loop.add_reader'
# go through.
await tasks.sleep(0, loop=self)
await tasks.sleep(0)

return server

Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_asyncio/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def test_get_with_waiting_putters(self):

def test_why_are_getters_waiting(self):
# From issue #268.
asyncio.set_event_loop(self.loop)

async def consumer(queue, num_expected):
for _ in range(num_expected):
Expand All @@ -276,8 +277,7 @@ async def create_queue():

self.loop.run_until_complete(
asyncio.gather(producer(q, producer_num_items),
consumer(q, producer_num_items),
loop=self.loop),
consumer(q, producer_num_items)),
)

def test_cancelled_getters_not_being_held_in_self_getters(self):
Expand Down Expand Up @@ -498,6 +498,7 @@ def test_put_with_waiting_getters(self):

def test_why_are_putters_waiting(self):
# From issue #265.
asyncio.set_event_loop(self.loop)

async def create_queue():
q = asyncio.Queue(2)
Expand All @@ -519,8 +520,7 @@ async def getter():
t1 = putter(1)
t2 = putter(2)
t3 = putter(3)
self.loop.run_until_complete(
asyncio.gather(getter(), t0, t1, t2, t3, loop=self.loop))
self.loop.run_until_complete(asyncio.gather(getter(), t0, t1, t2, t3))

def test_cancelled_puts_not_being_held_in_self_putters(self):
def a_generator():
Expand Down
20 changes: 0 additions & 20 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,26 +635,6 @@ async def execute():

self.assertIsNone(self.loop.run_until_complete(execute()))

def test_exec_loop_deprecated(self):
async def go():
with self.assertWarns(DeprecationWarning):
proc = await asyncio.create_subprocess_exec(
sys.executable, '-c', 'pass',
loop=self.loop,
)
await proc.wait()
self.loop.run_until_complete(go())

def test_shell_loop_deprecated(self):
async def go():
with self.assertWarns(DeprecationWarning):
proc = await asyncio.create_subprocess_shell(
"exit 0",
loop=self.loop,
)
await proc.wait()
self.loop.run_until_complete(go())


if sys.platform != 'win32':
# Unix
Expand Down
Loading