Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finish the module docs.
  • Loading branch information
ericsnowcurrently committed May 23, 2017
commit 4e07f7ab07b3667f429aa6b3fb18941030a489ed
36 changes: 20 additions & 16 deletions Doc/library/_interpreters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@

.. versionadded:: 3,7

:ref:`_sub-interpreter-support`

threading

--------------

This module provides low-level primitives for working with multiple
Python interpreters in the same process.

Python interpreters in the same runtime in the current process.
.. XXX The :mod:`interpreters` module provides an easier to use and
higher-level API built on top of this module.

More information about (sub)interpreters is found at
:ref:`_sub-interpreter-support`, including what data is shared between
interpreters and what is unique. Note particularly that interpreters
aren't inherently threaded, even though they track and manage Python
threads. To run code in an interpreter in a different OS thread, call
:func:`run_string` in a function that you run in a new Python thread.
For example::

id = _interpreters.create()
def f():
_interpreters.run_string(id, 'print("in a thread")')

t = threading.Thread(target=f)
t.start()

This module is optional. It is provided by Python implementations which
support multiple interpreters.

.. XXX For systems lacking the :mod:`_interpreters` module, the
:mod:`_dummy_interpreters` module is available. It duplicates this
module's interface and can be used as a drop-in replacement.
Expand All @@ -42,9 +51,10 @@ It defines the following functions:
.. function:: run_string(id, command)

A wrapper around :c:func:`PyRun_SimpleString` which runs the provided
Python program using the identified interpreter. Providing an
invalid or unknown ID results in a RuntimeError, likewise if the main
interpreter or any other running interpreter is used.
Python program in the main thread of the identified interpreter.
Providing an invalid or unknown ID results in a RuntimeError,
likewise if the main interpreter or any other running interpreter
is used.

Any value returned from the code is thrown away, similar to what
threads do. If the code results in an exception then that exception
Expand All @@ -62,9 +72,3 @@ It defines the following functions:
merged into the execution namespace before execution. Note that
this allows objects to leak between interpreters, which may not
be desirable.


**Caveats:**

* ...