Skip to content

Commit dfa20f9

Browse files
committed
mark task before it runs eagerly
1 parent 9a8733b commit dfa20f9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Modules/_asynciomodule.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,9 +2190,6 @@ register_task(_PyThreadStateImpl *ts, TaskObj *task)
21902190
assert(task->task_node.prev != NULL);
21912191
return;
21922192
}
2193-
#ifdef Py_GIL_DISABLED
2194-
_PyObject_SetMaybeWeakref((PyObject *)task);
2195-
#endif
21962193
struct llist_node *head = &ts->asyncio_tasks_head;
21972194
llist_insert_tail(head, &task->task_node);
21982195
}
@@ -2369,6 +2366,11 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
23692366
return -1;
23702367
}
23712368
_PyThreadStateImpl *ts = (_PyThreadStateImpl *)_PyThreadState_GET();
2369+
#ifdef Py_GIL_DISABLED
2370+
// This is required so that _Py_TryIncref(self)
2371+
// works correctly in non-owning threads.
2372+
_PyObject_SetMaybeWeakref((PyObject *)self);
2373+
#endif
23722374
if (eager_start) {
23732375
PyObject *res = PyObject_CallMethodNoArgs(loop, &_Py_ID(is_running));
23742376
if (res == NULL) {

0 commit comments

Comments
 (0)