[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

handling asynchronous callbacks from c++ in a python script

Tim Spens

1/23/2008 11:47:00 PM

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=Ahu06i62sR8HDtDypa...


1 Answer

Aaron Brady

1/24/2008 6:35:00 AM

0

On Jan 23, 5:46 pm, Tim Spens <t_sp...@yahoo.com> wrote:
> 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 )