classification
Title: Task.current_task(None) returns unexpected result
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: azazel, inada.naoki, lelit, yselivanov
Priority: normal Keywords: patch

Created on 2017-01-13 22:11 by yselivanov, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
task.patch yselivanov, 2017-01-13 22:17 review
Pull Requests
URL Status Linked Edit
PR 406 merged yselivanov, 2017-03-02 22:35
PR 413 merged yselivanov, 2017-03-03 03:25
PR 703 larry, 2017-03-17 21:00
PR 552 closed dstufft, 2017-03-31 16:36
Messages (6)
msg285445 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-01-13 22:11
Quoting Alberto Berdi from python-tulip mailing list:

working with the Python 3.6 asyncio implemented in C, i've got what is
for me a strange behavior of the asyncio.Task.current task
function. Executing the following test:

 import asyncio

 async def coro():
     print(asyncio.Task.current_task())
     print(asyncio.Task.current_task(None))
     print(asyncio.Task.current_task(loop=asyncio.get_event_loop()))

 loop = asyncio.get_event_loop()
 loop.run_until_complete(coro())

in Py3.5, I obtain the result:

<Task pending coro=<coro() running at test_task.py:4> cb=[_run_until_complete_cb() at /usr/lib/python3.5/asyncio/base_events.py:176]>
<Task pending coro=<coro() running at test_task.py:5> cb=[_run_until_complete_cb() at /usr/lib/python3.5/asyncio/base_events.py:176]>
<Task pending coro=<coro() running at test_task.py:6> cb=[_run_until_complete_cb() at /usr/lib/python3.5/asyncio/base_events.py:176]>

In Py3.6, i get:

<Task pending coro=<coro() running at test_task.py:4> cb=[_run_until_complete_cb() at /usr/lib/python3.6/asyncio/base_events.py:176]>
None
<Task pending coro=<coro() running at test_task.py:6> cb=[_run_until_complete_cb() at /usr/lib/python3.6/asyncio/base_events.py:176]>

What's going on here? It's still right to expect the same result from the three calls or something has changed?
The documentation for the Task.current_task() function seems unchanged between the two version.

My python3.6 has version:

$ python3.6 -VV
Python 3.6.0 (default, Dec 29 2016, 04:29:02) 
[GCC 6.2.1 20161215]
msg285447 - (view) Author: Lele Gaifax (lelit) * Date: 2017-01-13 22:57
FWIW, the problem afflicts other functions, for example the following script exhibits a similar difference:

import asyncio

async def coro():
    print(asyncio.Task.all_tasks())
    print(asyncio.Task.all_tasks(None))

loop = asyncio.get_event_loop()
loop.run_until_complete(coro())
msg285448 - (view) Author: Lele Gaifax (lelit) * Date: 2017-01-13 23:01
Yay, Yury is too fast!! :-)
msg285456 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2017-01-14 02:39
LGTM
msg288855 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-03 04:20
New changeset 13802a3b11eb5202b16e464cbfb85c144f8581ce by Yury Selivanov in branch '3.6':
bpo-29271: Fix Task.current_task and Task.all_tasks to accept None. (#406)
https://github.com/python/cpython/commit/13802a3b11eb5202b16e464cbfb85c144f8581ce
msg290338 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-03-24 23:08
New changeset 8d26aa930c0123933a1ceb12fceba4f5aef4e95e by Yury Selivanov in branch 'master':
bpo-29271: Fix Task.current_task and Task.all_tasks to accept None. (#406)
https://github.com/python/cpython/commit/8d26aa930c0123933a1ceb12fceba4f5aef4e95e
History
Date User Action Args
2017-03-31 16:36:33dstufftsetpull_requests: + pull_request1062
2017-03-24 23:08:55yselivanovsetmessages: + msg290338
2017-03-17 21:00:33larrysetpull_requests: + pull_request591
2017-03-03 23:10:28yselivanovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-03-03 04:20:31yselivanovsetmessages: + msg288855
2017-03-03 03:25:10yselivanovsetpull_requests: + pull_request344
2017-03-02 22:35:14yselivanovsetpull_requests: + pull_request338
2017-01-14 02:39:31inada.naokisetmessages: + msg285456
2017-01-13 23:01:26lelitsetmessages: + msg285448
2017-01-13 22:57:20lelitsetmessages: + msg285447
2017-01-13 22:31:21gvanrossumsetnosy: - gvanrossum
2017-01-13 22:28:00lelitsetnosy: + lelit
2017-01-13 22:26:22azazelsetnosy: + azazel
2017-01-13 22:17:41yselivanovsetfiles: + task.patch
nosy: + inada.naoki
keywords: + patch
2017-01-13 22:11:24yselivanovcreate