Skip to content

Commit 8a1c13d

Browse files
use _PyObject_SetMaybeWeakref
1 parent 599be68 commit 8a1c13d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Modules/_asynciomodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#endif
44

55
#include "Python.h"
6+
#include "pycore_object.h" // _PyObject_SetMaybeWeakref
67
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION_MUT()
78
#include "pycore_dict.h" // _PyDict_GetItem_KnownHash()
89
#include "pycore_freelist.h" // _Py_FREELIST_POP()
@@ -2226,6 +2227,11 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
22262227
if (task_call_step_soon(state, self, NULL)) {
22272228
return -1;
22282229
}
2230+
#ifdef Py_GIL_DISABLED
2231+
// This is required so that _Py_TryIncref(self)
2232+
// works correctly in non-owning threads.
2233+
_PyObject_SetMaybeWeakref((PyObject *)self);
2234+
#endif
22292235
register_task(state, self);
22302236
return 0;
22312237
}

0 commit comments

Comments
 (0)