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
8d26aa93
Commit
8d26aa93
authored
Mar 02, 2017
by
Yury Selivanov
Committed by
GitHub
Mar 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29271: Fix Task.current_task and Task.all_tasks to accept None. (#406)
parent
ba7e1f9a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
9 deletions
+29
-9
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+17
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_asynciomodule.c
Modules/_asynciomodule.c
+6
-6
Modules/clinic/_asynciomodule.c.h
Modules/clinic/_asynciomodule.c.h
+3
-3
No files found.
Lib/test/test_asyncio/test_tasks.py
View file @
8d26aa93
...
...
@@ -1461,6 +1461,14 @@ class BaseTaskTests:
def
coro
(
loop
):
self
.
assertTrue
(
Task
.
current_task
(
loop
=
loop
)
is
task
)
# See http://bugs.python.org/issue29271 for details:
asyncio
.
set_event_loop
(
loop
)
try
:
self
.
assertIs
(
Task
.
current_task
(
None
),
task
)
self
.
assertIs
(
Task
.
current_task
(),
task
)
finally
:
asyncio
.
set_event_loop
(
None
)
task
=
self
.
new_task
(
self
.
loop
,
coro
(
self
.
loop
))
self
.
loop
.
run_until_complete
(
task
)
self
.
assertIsNone
(
Task
.
current_task
(
loop
=
self
.
loop
))
...
...
@@ -1805,8 +1813,17 @@ class BaseTaskTests:
# schedule the task
coro
=
kill_me
(
self
.
loop
)
task
=
asyncio
.
ensure_future
(
coro
,
loop
=
self
.
loop
)
self
.
assertEqual
(
Task
.
all_tasks
(
loop
=
self
.
loop
),
{
task
})
# See http://bugs.python.org/issue29271 for details:
asyncio
.
set_event_loop
(
self
.
loop
)
try
:
self
.
assertEqual
(
Task
.
all_tasks
(),
{
task
})
self
.
assertEqual
(
Task
.
all_tasks
(
None
),
{
task
})
finally
:
asyncio
.
set_event_loop
(
None
)
# execute the task so it waits for future
self
.
loop
.
_run_once
()
self
.
assertEqual
(
len
(
self
.
loop
.
_ready
),
0
)
...
...
Misc/NEWS
View file @
8d26aa93
...
...
@@ -256,6 +256,9 @@ Extension Modules
Library
-------
-
bpo
-
29271
:
Fix
Task
.
current_task
and
Task
.
all_tasks
implemented
in
C
to
accept
None
argument
as
their
pure
Python
implementation
.
-
bpo
-
29703
:
Fix
asyncio
to
support
instantiation
of
new
event
loops
in
child
processes
.
...
...
Modules/_asynciomodule.c
View file @
8d26aa93
...
...
@@ -1414,7 +1414,7 @@ TaskObj_get_fut_waiter(TaskObj *task)
@classmethod
_asyncio.Task.current_task
loop: 'O' = N
ULL
loop: 'O' = N
one
Return the currently running task in an event loop or None.
...
...
@@ -1425,11 +1425,11 @@ None is returned when called not in the context of a Task.
static
PyObject
*
_asyncio_Task_current_task_impl
(
PyTypeObject
*
type
,
PyObject
*
loop
)
/*[clinic end generated code: output=99fbe7332c516e03 input=
cd784537f02cf833
]*/
/*[clinic end generated code: output=99fbe7332c516e03 input=
a0d6cdf2e3b243e1
]*/
{
PyObject
*
res
;
if
(
loop
==
NULL
)
{
if
(
loop
==
Py_None
)
{
loop
=
_PyObject_CallNoArg
(
asyncio_get_event_loop
);
if
(
loop
==
NULL
)
{
return
NULL
;
...
...
@@ -1501,7 +1501,7 @@ fail:
@classmethod
_asyncio.Task.all_tasks
loop: 'O' = N
ULL
loop: 'O' = N
one
Return a set of all tasks for an event loop.
...
...
@@ -1510,11 +1510,11 @@ By default all tasks for the current event loop are returned.
static
PyObject
*
_asyncio_Task_all_tasks_impl
(
PyTypeObject
*
type
,
PyObject
*
loop
)
/*[clinic end generated code: output=11f9b20749ccca5d input=c
d64aa5f88bd5c49
]*/
/*[clinic end generated code: output=11f9b20749ccca5d input=c
6f5b53bd487488f
]*/
{
PyObject
*
res
;
if
(
loop
==
NULL
)
{
if
(
loop
==
Py_None
)
{
loop
=
_PyObject_CallNoArg
(
asyncio_get_event_loop
);
if
(
loop
==
NULL
)
{
return
NULL
;
...
...
Modules/clinic/_asynciomodule.c.h
View file @
8d26aa93
...
...
@@ -278,7 +278,7 @@ _asyncio_Task_current_task(PyTypeObject *type, PyObject **args, Py_ssize_t nargs
PyObject
*
return_value
=
NULL
;
static
const
char
*
const
_keywords
[]
=
{
"loop"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"|O:current_task"
,
_keywords
,
0
};
PyObject
*
loop
=
NULL
;
PyObject
*
loop
=
Py_None
;
if
(
!
_PyArg_ParseStackAndKeywords
(
args
,
nargs
,
kwnames
,
&
_parser
,
&
loop
))
{
...
...
@@ -310,7 +310,7 @@ _asyncio_Task_all_tasks(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, P
PyObject
*
return_value
=
NULL
;
static
const
char
*
const
_keywords
[]
=
{
"loop"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"|O:all_tasks"
,
_keywords
,
0
};
PyObject
*
loop
=
NULL
;
PyObject
*
loop
=
Py_None
;
if
(
!
_PyArg_ParseStackAndKeywords
(
args
,
nargs
,
kwnames
,
&
_parser
,
&
loop
))
{
...
...
@@ -517,4 +517,4 @@ _asyncio_Task__wakeup(TaskObj *self, PyObject **args, Py_ssize_t nargs, PyObject
exit:
return
return_value
;
}
/*[clinic end generated code: output=
07a15bbb28d03ed
c input=a9049054013a1b77]*/
/*[clinic end generated code: output=
3dfec49689cebd4
c input=a9049054013a1b77]*/
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