Multiple independent Python interpreters in a C/C++ program?

sturlamolden sturlamolden at yahoo.no
Sat Apr 12 13:00:07 EDT 2008


On Apr 11, 6:24 pm, s... at pobox.com wrote:

> Do I wind up with two completely independent interpreters, one per thread?
> I'm thinking this doesn't work (there are bits which aren't thread-safe and
> are only protected by the GIL), but wanted to double-check to be sure.

You can create a new interpreter with a call to Py_NewInterpreter.

However, the GIL is a global object for the process. If you have more
than two interpreters in the process, they share the same GIL.

In tcl, each thread has its own interpreter instance and no GIL is
shared. This circumvents most of the problems with a global GIL.

In theory, a GIL private to each interpreter would make Python more
scalable. The current GIL behaves like the BKL in earlier Linux
kernels. However, some third-party software, notably Apache's
mod_python, is claimed to depend on this behaviour.





More information about the Python-list mailing list