PEP 630 -- Isolating Extension Modules

A few weeks ago (before a short vacation) marked my Informational PEP 630 as Active. I encourage anyone who uses Python’s C-API to read it. It includes a practical introduction to the “new” module-related C-API.
The new API is not complete for all use cases (see Open Issues), so I am not trying to integrate the text into Python’s documentation, but it should be good for early adopters (including Python’s stdlib) and API critics. In fact, the PEP includes most answers I gave to these people :‌)

I should also mention that the PEP is not about all recent activity around the C-API – for example the effort to eventually eliminate all static types is orthogonal.

Personally, the PEP summarizes my last 5 years of contributing to CPython. Thank to everyone who helped, ans especially @ncoghlan who got me started, way back in 2015.



But proving the point about C level statics being dangerous: in the absence of the GIL, there’s a time-of-check/time-of-use race condition in the example “opt-out” code.

I don’t think there’s a simple cross-platform way to fix that though, so we may just need to keep a global “C extension module initialisation” lock even if we some day manage to make the GIL itself truly an “interpreter” level lock.

1 Like