Skip to content

Commit 10a7356

Browse files
committed
Add some docs cross references
1 parent 988c61f commit 10a7356

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

docs/advanced/embedding.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

253253
A sub-interpreter is a separate interpreter instance which provides a
254254
separate, isolated interpreter environment within the same process as the main
255255
interpreter. Sub-interpreters are created and managed with a separate API from
256256
the main interpreter. Beginning in Python 3.12, sub-interpreters each have
257257
their own Global Interpreter Lock (GIL), which means that running a
258258
sub-interpreter in a separate thread from the main interpreter can achieve true
259-
concurrency.
259+
concurrency.
260260

261261
pybind11'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.
266266
Proceed with caution (and lots of testing)!
267267

268268
The 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
308308
manage the GIL of a sub-interpreter just as they do for the main interpreter.
309309
They 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
311311
caveat:
312312

313313
.. note::
@@ -319,7 +319,7 @@ caveat:
319319

320320
Each sub-interpreter will import a separate copy of each ``PYBIND11_EMBEDDED_MODULE``
321321
when 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``
323323
if it is imported in a sub-interpreter.
324324

325325
Here is an example showing how to create and activate sub-interpreters:
@@ -393,8 +393,8 @@ it when it goes out of scope.
393393

394394
Best 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`.

docs/advanced/misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ You can explicitly disable sub-interpreter support in your module by using the
228228
:func:`multiple_interpreters::not_supported()` tag. This is the default behavior if you do not
229229
specify a multiple_interpreters tag.
230230

231+
.. _misc_concurrency:
232+
231233
Concurrency and Parallelism in Python with pybind11
232234
===================================================
233235

0 commit comments

Comments
 (0)