https://github.com/python/cpython/commit/bff4bfeae1f428a815dc9a57b87f913217188fdd
commit: bff4bfeae1f428a815dc9a57b87f913217188fdd
branch: main
author: Kumar Aditya <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-02-10T15:04:33+05:30
summary:
gh-128002: add fast path for native tasks in `asyncio.all_tasks` (#129943)
files:
M Modules/_asynciomodule.c
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 4070076d756fcf..449c8a9499261a 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -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;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]