handling asynchronous callbacks from c++ in a python script

T

Tim Spens

I have a c++ program running that has boost python hooks for the c++ api.
I'm running a python client that makes calls into the c++ api. The problem is there are c++
asynchronous callbacks that need to pass information to the python client. What I was hoping to
do is call a python function from c++ that resides in the running "main()" python client
while in the c++ callback handlers.
Is this possible and if you can point me to an example or documentation on how to do this it would be much appreciated?

NOTE: I've been asking on the c++-sig mailing list about this and David Abrahams (very well versed in boost python) said:
"I'm not an expert on asynchronous python and this is really not a Boost.Python question. I suggest you ask on the regular Python mailing list. Sorry."





____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
 
C

castironpi

I have a c++ program running that has boost python hooks for the c++ api.
I'm running a python client that makes calls into the c++ api. The problem is there are c++
asynchronous callbacks that need to pass information to the python client. What I was hoping to
do is call a python function from c++ that resides in the running "main()" python client
while in the c++ callback handlers.
Is this possible and if you can point me to an example or documentation on how to do this it would be much appreciated?

NOTE: I've been asking on the c++-sig mailing list about this and David Abrahams (very well versed in boost python) said:
"I'm not an expert on asynchronous python and this is really not a Boost.Python question. I suggest you ask on the regular Python mailing list. Sorry."

PyObject_CallFunction.

You might need to pass -out- a Thread instance, initialized with your
callback, then just call start, or just the pointer to start.

import threading
import time
def f( func )
func()

def g( caption ):
for _ in range( 1000 ):
print '%s\n'% caption,
time.sleep( .01 )

th= threading.Thread( target= g, args= ( 'what' ) )
f( th.start )
time.sleep( 10 )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top