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

Diez B. Roggisch deets at nospam.web.de
Fri Apr 11 13:03:25 EDT 2008


skip at pobox.com schrieb:
> 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.

AFAIK there was a thread a few month ago that stated that this is 
actually possible - but mostly 3rd-party-c-extension aren't capable of 
supporting that. Martin von Loewis had a word in that, maybe googling 
with that in mind reveals the discussion.

And of course its a *bad* idea to pass objects between threads...

Diez



More information about the Python-list mailing list