[Python-ideas] PEP 554: Stdlib Module to Support Multiple Interpreters in Python Code
ericsnowcurrently at gmail.com
Thu Sep 7 14:26:18 EDT 2017
As part of the multi-core work I'm proposing the addition of the
"interpreters" module to the stdlib. This will expose the existing
subinterpreters C-API to Python code. I've purposefully kept the API
simple. Please let me know what you think.
Title: Multiple Interpreters in the Stdlib
Author: Eric Snow <ericsnowcurrently at gmail.com>
Type: Standards Track
This proposal introduces the stdlib "interpreters" module. It exposes
the basic functionality of subinterpreters that exists in the C-API.
Running code in multiple interpreters provides a useful level of
isolation within the same process. This can be leveraged in number
of ways. Furthermore, subinterpreters provide a well-defined framework
in which such isolation may extended.
CPython has supported subinterpreters, with increasing levels of
support, since version 1.5. While the feature has the potential
to be a powerful tool, subinterpreters have suffered from neglect
because they are not available directly from Python. Exposing the
existing functionality in the stdlib will help reverse the situation.
The "interpreters" module will be added to the stdlib. It will
provide a high-level interface to subinterpreters and wrap the low-level
"_interpreters" module. The proposed API is inspired by the
The module provides the following functions:
Return a list of all existing interpreters.
Return the currently running interpreter.
Return the main interpreter.
Initialize a new Python interpreter and return it. The
interpreter will be created in the current thread and will remain
idle until something is run in it.
The module also provides the following class:
The interpreter's ID (read-only).
Return whether or not the interpreter is currently running.
Finalize and destroy the interpreter.
Run the provided Python code in the interpreter, in the current
OS thread. Supported code: source text.
This document has been placed in the public domain.
More information about the Python-ideas