[C++-sig] Re: calling a python-callback-function from a c++thread...

David Abrahams dave at boost-consulting.com
Fri Sep 26 23:49:52 CEST 2003

Lars Kunert <lkunert at mpi-sb.mpg.de> writes:

> Hi!
> I am trying to implement a Qt-application, which after beeing lauched from 
> the IDLE creates and lives on its own thread. The idea is, that the 
> program may be called from other python-programs and may itself call other 
> python programs.
> Python-functions, which should be called from the program, register 
> themself prior to their invocation. I think my problem is that I do not 
> aquire the python-interpreter lock before using the callback...
> PyApp.* wraps QtApplication by exporting selected methods to pyton, 
> launches the thread, QtApp lives on, and locks/unlockes (syncs) accesses 
> to the internal state of QtApp.
> PyApp.h

Are you sure that when your QtApp::callback() is invoked it's on the
same thread as the Python interpreter?

See http://www.python.org/peps/pep-0311.html and the related sections
of the Python/'C' API documentation if you don't know what I mean.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list