From d04497d60cd2ca34cc6315668c3800f05038e124 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 8 Sep 2017 11:59:32 -0700 Subject: [PATCH] Add a section about interpreter isolation. (#400) --- pep-0554.rst | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pep-0554.rst b/pep-0554.rst index 726bf26be..9984b242b 100644 --- a/pep-0554.rst +++ b/pep-0554.rst @@ -14,8 +14,8 @@ Abstract This proposal introduces the stdlib ``interpreters`` module. It exposes the basic functionality of subinterpreters that already exists in the -C-API. Each subinterpreter runs with its own state, including its own -copy of all modules, classes, functions, and variables. +C-API. Each subinterpreter runs with its own state (see +``Interpreter Isolation`` below). Rationale @@ -133,12 +133,41 @@ interpreters via queues. The minimal solution (running a source string) is sufficient for us to get the feature out where it can be explored. +Interpreter Isolation +===================== + +CPython's interpreters are intended to be strictly isolated from each +other. Each interpreter has its own copy of all modules, classes, +functions, and variables. The same applies to state in C, including in +extension modules. The CPython C-API docs explain more. [c-api]_ + +However, there are ways in which interpreters share some state. First +of all, some process-global state remains shared, like file descriptors. +There are no plans to change this. + +Second, some isolation is faulty due to bugs or implementations that did +not take subinterpreters into account. This includes things like +at-exit handlers and extension modules that rely on C globals. In these +cases bugs should be opened (some are already). + +Finally, some potential isolation is missing due to the current design +of CPython. This includes the GIL and memory management. Improvements +are currently going on to address gaps in this area. + + Open Questions ============== * Add queues to the proposal anyway? +References +========== + +.. [c-api] + https://docs.python.org/3/c-api/init.html#bugs-and-caveats + + Copyright =========