You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
arraymodule, _decimal: possible lazy import caches reference leaks in free-threaded builds #149006
I was wondering about the lazy init pattern in a free-threaded build. If two threads enter build_struct_time concurrently with st->time_struct_time == NULL, both would call PyImport_ImportModuleAttrString and one overwrite would leave a reference with an incremented refcount that never gets decref'd.
I noticed arraymodule.c and _decimal.c have the same pattern, so maybe this is just accepted. But _asynciomodule.c initializes eagerly in module_init() which avoids this structurally. Was lazy chosen deliberately here over eager init in init_state()?
While I've addressed this in #148088, I think that this is a valid concern, and import caches should use CAS, just like:
changed the title [-]Possible lazy import caches reference leaks in free-threaded builds[/-][+]`arraymodule`, `_decimal`: possible lazy import caches reference leaks in free-threaded builds[/+]on Apr 26, 2026
Activity
[-]Possible lazy import caches reference leaks in free-threaded builds[/-][+]`arraymodule`, `_decimal`: possible lazy import caches reference leaks in free-threaded builds[/+]htjworld commentedon Apr 26, 2026
Hi @maurycy — interested in helping with this one. Happy to follow your lead since you opened it, but a couple of things I could pick up:
arraymodule.cor_decimal.c, whichever you're not already onOr if you'd rather drive both, happy to just review. Let me know what works.
maurycy commentedon Apr 26, 2026
I'm not a core dev! Let's wait for a green light from the higher ups :-)