Closed
Labels
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2018-10-02.17:59:06.584>
created_at = <Date 2018-09-18.21:44:05.146>
labels = ['easy', 'type-feature', '3.8', 'expert-asyncio']
title = 'deprecate *loop* argument for asyncio.sleep'
updated_at = <Date 2018-10-02.17:59:06.583>
user = 'https://github.com/1st1'bugs.python.org fields:
activity = <Date 2018-10-02.17:59:06.583>
actor = 'yselivanov'
assignee = 'none'
closed = True
closed_date = <Date 2018-10-02.17:59:06.584>
closer = 'yselivanov'
components = ['asyncio']
creation = <Date 2018-09-18.21:44:05.146>
creator = 'yselivanov'
dependencies = []
files = []
hgrepos = []
issue_num = 34728
keywords = ['patch', 'easy']
message_count = 12.0
messages = ['325684', '325685', '326213', '326825', '326826', '326832', '326862', '326863', '326864', '326866', '326890', '326891']
nosy_count = 7.0
nosy_names = ['vstinner', 'asvetlov', 'serhiy.storchaka', 'yselivanov', 'willingc', 'xtreak', 'fbidu']
pr_nums = ['9415', '9661']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue34728'
versions = ['Python 3.8']
Activity
1st1 commentedon Sep 18, 2018
asyncio.sleep is a coroutine; passing a *loop* argument to it makes no sense anymore.
We should raise a DeprecationWarning in Python 3.8 and 3.9 and remove it in 4.0.
1st1 commentedon Sep 18, 2018
Same for asyncio.wait and asyncio.wait_for.
willingc commentedon Sep 24, 2018
New changeset 558c49b by Carol Willing (João Júnior) in branch 'master':
bpo-34728: Remove deprecate *loop* argument in asyncio.sleep (GH-9415)
558c49b
serhiy-storchaka commentedon Oct 1, 2018
Tests are failed when ran with -Werror.
$ ./python -Werror -m test -vuall test_asyncgen ...======================================================================
ERROR: test_async_gen_asyncio_01 (test.test_asyncgen.AsyncGenAsyncioTest)
----------------------------------------------------------------------
======================================================================
...
(the full log is too long)
$ ./python -Werror -m test -vuall test_asyncio ...======================================================================
FAIL: test_sleep_cancel (test.test_asyncio.test_tasks.PyTask_PyFuture_SubclassTests)
----------------------------------------------------------------------
======================================================================
FAIL: test_run_coroutine_threadsafe_task_factory_exception (test.test_asyncio.test_tasks.RunCoroutineThreadsafeTests)
Test coroutine submission from a tread to an event loop
----------------------------------------------------------------------
...
(the full log is too long)
vstinner commentedon Oct 1, 2018
On python-committers, it has been said that 3.10 will follow Python 3.9, no?
1st1 commentedon Oct 1, 2018
Victor, you're looking at an outdated comment on this issue. This is what's in the master branch:
cpython/Lib/asyncio/tasks.py
Lines 598 to 599 in d4c76d9
vstinner commentedon Oct 2, 2018
No, I read the commit:
558c49b
cpython/Lib/asyncio/tasks.py
Lines 598 to 599 in d4c76d9
Ah, you forgot to mention this bpo in your commit:
commit fad6af2
Author: Yury Selivanov <[email protected]>
Date: Tue Sep 25 17:44:52 2018 -0400
Anyway, the current code is fine. Thanks.
vstinner commentedon Oct 2, 2018
There is a new PR, so I change the issue resolution again.
vstinner commentedon Oct 2, 2018
FYI if I recall correctly, in the past, we preferred to pass explicitly the loop to avoid to have to get the current loop which may add an overhead. But the current trend is to get rid of the explicit loop parameter.
sleep() requires the current event loop:
Why does it not make sense to pass the loop to sleep? "it makes no sense anymore" something changes?
I'm not against the change, I'm just trying to understand the rationale for other changes :-)
asvetlov commentedon Oct 2, 2018
My understanding is:
loopargument passed to sleep should be always the same as returned fromget_running_loop().Passing it explicitly can be considered as microoptimization but
get_running_loop()is pretty fast now, no need for such micro-opts.On another hand passing *non-current* loop is a serious error: nothing prevents to do it but the code just hangs.
1st1 commentedon Oct 2, 2018
New changeset 9012a0f by Yury Selivanov in branch 'master':
bpo-34728: Fix asyncio tests to run under "-Werror" (GH-9661)
9012a0f
1st1 commentedon Oct 2, 2018
[victor]
[andrew]
loopargument passed to sleep should be always the same as returned fromget_running_loop().What Andrew said.
Basically, it wasn't *ever* possible to pass a loop to sleep() that would be different from the loop that would run it, because sleep() is a *coroutine*.
In asyncio some APIs are functions and some are coroutines.
asyncio.gather(), for example, is a function. You can call it from top-level code (and pass an event loop to it) or from a coroutine.
asyncio.sleep(), wait(), and wait_for() are *coroutines*; they can only be called from other coroutines or if you wrap them into a Task; in all cases, *loop* is always 100% defined for them.
Passing the loop isn't even a viable micro-optimization, it's just pointless. This extra argument just adds to the confusion and promotes bad patterns, so we want to eventually remove it.