@@ -247,22 +247,22 @@ global data. All the details can be found in the CPython documentation.
247247
248248.. _subinterp :
249249
250- Sub-interpreter support
251- =======================
250+ Embedding Sub-interpreters
251+ ==========================
252252
253253A sub-interpreter is a separate interpreter instance which provides a
254254separate, isolated interpreter environment within the same process as the main
255255interpreter. Sub-interpreters are created and managed with a separate API from
256256the main interpreter. Beginning in Python 3.12, sub-interpreters each have
257257their own Global Interpreter Lock (GIL), which means that running a
258258sub-interpreter in a separate thread from the main interpreter can achieve true
259- concurrency.
259+ concurrency.
260260
261261pybind11's sub-interpreter API can be found in ``pybind11/subinterpreter.h ``.
262262
263- pybind11 :class: `subinterpreter ` instances can be safely moved and shared between
264- threads as needed. However, managing multiple threads and the lifetimes of multiple
265- interpreters and their GILs can be challenging.
263+ pybind11 :class: `subinterpreter ` instances can be safely moved and shared between
264+ threads as needed. However, managing multiple threads and the lifetimes of multiple
265+ interpreters and their GILs can be challenging.
266266Proceed with caution (and lots of testing)!
267267
268268The main interpreter must be initialized before creating a sub-interpreter, and
@@ -307,7 +307,7 @@ sub-interpreters.
307307:class: `gil_scoped_release ` and :class: `gil_scoped_acquire ` can be used to
308308manage the GIL of a sub-interpreter just as they do for the main interpreter.
309309They both manage the GIL of the currently active interpreter, without the
310- programmer having to do anything special or different. There is one important
310+ programmer having to do anything special or different. There is one important
311311caveat:
312312
313313.. note ::
@@ -319,7 +319,7 @@ caveat:
319319
320320Each sub-interpreter will import a separate copy of each ``PYBIND11_EMBEDDED_MODULE ``
321321when those modules specify a ``multiple_interpreters `` tag. If a module does not
322- specify a ``multiple_interpreters `` tag, then Python will report an ``ImportError ``
322+ specify a ``multiple_interpreters `` tag, then Python will report an ``ImportError ``
323323if it is imported in a sub-interpreter.
324324
325325Here is an example showing how to create and activate sub-interpreters:
@@ -393,8 +393,8 @@ it when it goes out of scope.
393393
394394Best Practices for sub-interpreter safety:
395395
396- - Avoid moving or disarming RAII objects managing GIL and sub-interpreter lifetimes. Doing so can
397- lead to confusion about lifetimes. (For example, accidentally extending a
396+ - Avoid moving or disarming RAII objects managing GIL and sub-interpreter lifetimes. Doing so can
397+ lead to confusion about lifetimes. (For example, accidentally extending a
398398 :class: `subinterpreter_scoped_activate ` past the lifetime of it's :class: `subinterpreter `.)
399399
400400- Never share Python objects across different interpreters.
@@ -410,9 +410,11 @@ Best Practices for sub-interpreter safety:
410410 resulting Python object when the wrong interpreter was active.
411411
412412- While sub-interpreters each have their own GIL, there can now be multiple independent GILs in one
413- program you need to consider the possibility of deadlocks caused by multiple GILs and/or the
413+ program you need to consider the possibility of deadlocks caused by multiple GILs and/or the
414414 interactions of the GIL(s) and your C++ code's own locking.
415415
416416- When using multiple threads to run independent sub-interpreters, the independent GILs allow
417- concurrent calls from different interpreters into the same C++ code from different threads.
417+ concurrent calls from different interpreters into the same C++ code from different threads.
418418 So you must still consider the thread safety of your C++ code.
419+
420+ - Familiarize yourself with :ref: `misc_concurrency `.
0 commit comments