Problems embedding python 2.6 in C++

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 3 00:30:17 CET 2010


En Tue, 02 Feb 2010 02:26:57 -0300, Paul <gobladoome at gmail.com> escribió:

> I've managed to get it working and so far stable...

Glad to see you finally made it work!

> Current working version:
>   [...]
>  mycppclass::callpy(funcname, args...)
>       m_mypymodule = PyImport_Import(pModuleName)
>
>       pyargs = PyTuple_SetItem * args
>       PyCallable_Check(func)
>       PyObject_CallObject(func,pyargs)
>
>       Py_XDECREF(m_mypymodule)
>
> So now the module is being imported each function call (luckily I don't  
> have
> to worry about performance)

Remember that after the module is successfully imported by the first time,  
a subsequent import returns early, as soon as it finds the module in  
sys.modules[] -- the performance penalty shouldn't be so big.

> I assume this means that the internal representation of the imported  
> module
> is being corrupted by something. I found another person with a similar  
> issue
> here:
> http://mail.python.org/pipermail/python-dev/2004-March/043306.html -  
> that is
> a long time ago but another multi-threaded app.

> I'm happy to use the working method but I'd like to understand what is  
> going
> on a bit more. Can anyone shed any further light?

Sorry, I cannot help on this. Seems to happen only with an embedded  
interpreter and a multithreaded application, and I've never used Python in  
that scenario.

If you could trim your code to a minimal example that shows the faulty  
behavior, that would be great, so others can test it too and eventually  
determine what's going on.

-- 
Gabriel Genellina




More information about the Python-list mailing list