mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-128002: add fast path for native tasks in asyncio.all_tasks
(#129943)
This commit is contained in:
parent
7246b9124c
commit
bff4bfeae1
1 changed files with 13 additions and 0 deletions
|
@ -3991,6 +3991,19 @@ static inline int
|
|||
add_one_task(asyncio_state *state, PyObject *tasks, PyObject *task, PyObject *loop)
|
||||
{
|
||||
assert(PySet_CheckExact(tasks));
|
||||
if (Task_CheckExact(state, task)) {
|
||||
int pending = 0;
|
||||
Py_BEGIN_CRITICAL_SECTION(task);
|
||||
pending = ((TaskObj *)task)->task_state == STATE_PENDING && ((TaskObj *)task)->task_loop == loop;
|
||||
Py_END_CRITICAL_SECTION();
|
||||
if (pending) {
|
||||
if (PySet_Add(tasks, task) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *done = PyObject_CallMethodNoArgs(task, &_Py_ID(done));
|
||||
if (done == NULL) {
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue