How to call python from a foreign language thread (C++)

Mark Hammond skippy.hammond at gmail.com
Wed Feb 4 10:43:40 CET 2009


On 4/02/2009 4:51 AM, Victor Lin wrote:
> It may looks like this.
>
>      void operator() (double time, const AudioData&data) {
>          // acquire lock
>          m_Function(time, data);
>          // release lock
>      }

You want something like:

       void operator() (double time, const AudioData&data) {
           PyGILState_STATE old = PyGILState_Acquire();
           m_Function(time, data);
           PyGILState_Release(old);

Note that Phillip is also correct; you will need to initialize threading 
if this is an app which embeds Python...

HTH,

Mark



More information about the Python-list mailing list