using python interpreters per thread in C++ program

sturlamolden sturlamolden at
Mon Sep 7 07:55:03 CEST 2009

On 7 Sep, 07:17, grbgooglefan <ganeshbo... at> wrote:

> Can we not use python interpreters even private to each multiple
> thread?

You can use multiple interpreters, but they share GIL. For example,
Python extension modules are DLLs and will be loaded only once for
each process - the OS makes sure of that. Since they are objects too,
there can only be one GIL per process.

The same goes for files: If an interpreter calls close on a file
handle, it is closed for the whole process, not just locally to the
interpreter. Global synchronization is therefore needed. (Maybe not
for your threaded app, but for any conceivable use of Python.)

If you need two isolated interpreters, you need to run them in
different processes.

More information about the Python-list mailing list