concurrent.interpreters — Multiple interpreters in the same process — Python 3.16.0a0 documentation

docs.python.org

Tin mới

concurrent.futures — Launching parallel tasks

subprocess — Subprocess management

Python Module Index

3.16.0a0 Documentation

The Python Standard Library

Concurrent Execution

threading: Thread-based parallelism.

The concurrent.interpreters module constructs higher-level interfaces on top of the lower level _interpreters module.

Isolating Extension Modules

How to update an extension module to support multiple interpreters.

WebAssembly platforms

This module does not work or is not available on WebAssembly. See WebAssembly platforms for more information.

Running in an Interpreter¶

Running in a different interpreter involves switching to it in the current thread and then calling some function. The runtime will execute the function using the current interpreter’s state. The concurrent.interpreters m

Concurrency and Parallelism¶

As noted earlier, interpreters do not provide any concurrency on their own. They strictly represent the isolated execution context the runtime will use in the current thread. That isolation makes them similar to processe

Communication Between Interpreters¶

In practice, multiple interpreters are useful only if we have a way to communicate between them. This usually involves some form of message passing, but can even mean sharing data in some carefully managed way.

pickle: Convert Python objects to streams of bytes and back.

Any data actually shared between interpreters loses the thread-safety provided by the GIL. There are various options for dealing with this in extension modules. However, from Python code the lack of thread-safety means o