[C++-sig] Embedded Python and calling back into Python from C++

Stefan Seefeld seefeld at sympatico.ca
Thu Apr 5 16:44:30 CEST 2007


Ron Brown, Jr. wrote:
> I have what might be a ridiculous question for you all regarding 
> embedded python.  Hopefully I can explain it properly.  I'm going to 
> explain it within the context of Boost.Python, as that's what we're 
> planning on using.
> 
> If we write a Python module and also embed Python with Boost.Python, and 
> in the embedded python call back into C++, and then in that C++ call 
> back into Python, what happens?
> 
> I'll try and explain that a bit more clearly.
> 
> 1.) Write Python Module
> 2.) Embed Python Interpreter
> 3.) Import Python Module
> 4.) Call C++ function via Boost.Python from embedded Python
> 5.) Call Python function via Boost.Python from C++ function that was 
> originally called by Python
> 
> Is that possible?  Would Python's thread be busy waiting for the initial 
> C++ function to return?

That will work as any other call sequence. Python's Global Interpreter Lock
only comes into play when you use multiple threads all accessing the python
runtime. (And even then it is you who has to manually control the lock.)

HTH,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list