-
-
Notifications
You must be signed in to change notification settings - Fork 243
Description
Feature Request
In Python 3.10 ./configure you can pass option --with-experimental-isolated-subinterpreters (this just does #define EXPERIMENTAL_ISOLATED_SUBINTERPRETERS 1) which enables experimental feature of isolated interpreters, which allows to run multiple interpreters within separate Threads. There will be no GIL (global interpreter lock) anymore, each interpreter will have its separate Local interpreter lock.
This features allows to do within threads (single process) what multiprocessing module allowed to do between processes. Basically to use efficiently all cores of your CPU you don't need anymore to spawn separate processes, now you can spawn just threads within single process.
I think right now this feature can't be used within Python scripts code. Probably for now it is only available through Python C API. Meaning that only C/C++ applications can benefit from it right now. But I might be wrong. Also it should be available within Python scripts later as some special module/library probably in Python 3.11, when this feature becomes non-experimental.
For your python builds it would be great if this feature will be available as some configurable option (either within config file or some command-line option). Of course right now it shouldn't be enabled by default.
If you don't use ./configure (from Python sources) to build your scripts, then you just have to define
#define EXPERIMENTAL_ISOLATED_SUBINTERPRETERS 1
when compiling all .c files of Python. This feature spans many .c files so you have to do this define globally. Nothing else needed besides this define (as far as I can see when reading ./configure).
As far as I know implementing this feature needed to fix around 1500 places in the code. Mostly it needed making all global variables as thread local. And this thread local state is allocated separately for each interpreter's thread.
Don't know right now how Python objects are shared between these sub-interpreters, maybe only through serialization (marshaling), i.e. when converted to bytes. Or maybe they can be shared as read-only (if nothing mutates them at this moment). Have to investigate all the details, for that a good build of Python is needed to experiment.