-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-121621: Move asyncio freelist to thread state #121915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4822190
143747b
580304c
1faed12
ba3d771
ec2c175
e1b730a
f9fb6e1
c9ac6bb
b450b96
b3aa591
e514426
7786eeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,14 @@ struct _Py_object_stack_freelist { | |
Py_ssize_t numfree; | ||
}; | ||
|
||
|
||
struct _Py_asyncmodule_futureiter_freelist { | ||
#ifdef WITH_FREELISTS | ||
struct futureiterobject *fi_freelist; | ||
Py_ssize_t fi_freelist_len; | ||
#endif | ||
}; | ||
|
||
struct _Py_object_freelists { | ||
struct _Py_float_freelist floats; | ||
struct _Py_tuple_freelist tuples; | ||
|
@@ -135,6 +143,7 @@ struct _Py_object_freelists { | |
struct _Py_async_gen_freelist async_gens; | ||
struct _Py_async_gen_asend_freelist async_gen_asends; | ||
struct _Py_object_stack_freelist object_stacks; | ||
struct _Py_asyncmodule_futureiter_freelist futureiters; | ||
}; | ||
|
||
extern void _PyObject_ClearFreeLists(struct _Py_object_freelists *freelists, int is_finalization); | ||
|
@@ -147,6 +156,39 @@ extern void _PyAsyncGen_ClearFreeLists(struct _Py_object_freelists *freelists, i | |
extern void _PyContext_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization); | ||
extern void _PyObjectStackChunk_ClearFreeList(struct _Py_object_freelists *freelists, int is_finalization); | ||
|
||
// Keep in sync with _asynciomodule.c ! | ||
typedef struct futureiterobject_dummy { | ||
PyObject_HEAD | ||
void *future; | ||
} futureiterobject_dummy; | ||
|
||
static inline void | ||
_PyAsyncModule_ClearFreeLists(struct _Py_object_freelists *freelists, int is_finalization) | ||
{ | ||
#ifdef WITH_FREELISTS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anyone with better freelist internals knowledge know why this happens: When I remove this function's body, the refleak tests pass. Otherwise they currently fail. |
||
PyObject *next; | ||
PyObject *current; | ||
|
||
next = (PyObject*) freelists->futureiters.fi_freelist; | ||
while (next != NULL) { | ||
assert(freelists->futureiters.fi_freelist_len > 0); | ||
freelists->futureiters.fi_freelist_len--; | ||
|
||
current = next; | ||
next = (PyObject*) ((futureiterobject_dummy*) current)->future; | ||
PyObject_GC_Del(current); | ||
} | ||
assert(freelists->futureiters.fi_freelist_len == 0 || freelists->futureiters.fi_freelist_len == -1); | ||
freelists->futureiters.fi_freelist = NULL; | ||
if (is_finalization) { | ||
freelists->futureiters.fi_freelist_len = -1; | ||
} | ||
else { | ||
freelists->futureiters.fi_freelist_len = 0; | ||
} | ||
#endif | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by Sam we should try to find a way to avoid this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go with #121934, then that will make the asyncio freelist implementation a lot easier and will avoid a lot of these warts.
Maybe, in the meantime, we should just disable the freelist in the free-threaded build? That would be a much smaller change and wouldn't introduce duplicate types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could backport the disabling of freelist in the free-threaded build to 3.13 to fix the race conditions.