Skip to content

3.2 The State of Subinterpreters in CPython

Eric Snow edited this page May 31, 2023 · 1 revision

(Also see the slides for my lightning talk at the 2020 Python language summit.)

Status Quo (pre-2015)

While subinterpreters have been a part of C-Python for over 20 years, they haven't been heavily used. This is in large part because they were only exposed in the C-API (not in the stdlib) and the feature was not widely publicized. Furthermore, subinterpreters do not deal well with C global state. All this led to several problems:

Ongoing Improvements

  • PEP 3121 "Extension module initialization and finalization"
  • PEP 432 "Restructuring the CPython startup sequence"
  • PEP 489 "Multi-phase extension module initialization"
  • PEP 573 "Module State Access from C Extension Methods"

History

Key events:

  • added: ...
  • first used seriously: (mod_wsgi?) ...
  • GILState incompatibility
  • PEP 432
  • PEP 489

Known Projects Using Subinterpreters

Until relatively recently the only publicly known uses of subinterpreters were:

  • mod_wsgi
  • ???

However, in the last few years there has been an increased usage: