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

Rhamphoryncus rhamph at gmail.com
Sat Apr 12 11:56:58 EDT 2008


On Apr 11, 10:24 am, s... at pobox.com wrote:
> This question was posed to me today.  Given a C/C++ program we can clearly
> embed a Python interpreter in it.  Is it possible to fire up multiple
> interpreters in multiple threads?  For example:
>
>     C++ main
>         thread 1
>             Py_Initialize()
>         thread 2
>             Py_Initialize()
>
> 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.

Since they interpreters would never truly be separate, I think it's
best to bite the bullet and use multiple threads within one
interpreter.  The only really difference is pure python modules aren't
duplicated, but why would you need that?  Surely not for any kind of
security.



More information about the Python-list mailing list