handling asynchronous callbacks from c++ in a python script

Discussion in 'Python' started by Tim Spens, Jan 23, 2008.

  1. Tim Spens

    Tim Spens Guest

    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
     
    Tim Spens, Jan 23, 2008
    #1
    1. Advertising

  2. Tim Spens

    Guest

    On Jan 23, 5:46 pm, Tim Spens <> 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 )
     
    , Jan 24, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWljaGFlbFk=?=

    ASP.NET ICallbackHandler - Script callbacks....

    =?Utf-8?B?TWljaGFlbFk=?=, Jan 21, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,939
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 22, 2006
  2. kelly

    asp.net 2.0 script callbacks

    kelly, Jul 24, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    594
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 25, 2006
  3. =?Utf-8?B?TG93bGFuZGVy?=
    Replies:
    0
    Views:
    378
    =?Utf-8?B?TG93bGFuZGVy?=
    Mar 27, 2007
  4. jediknight

    asynchronous callbacks

    jediknight, Jun 18, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    358
    jediknight
    Jun 19, 2007
  5. Connor
    Replies:
    0
    Views:
    60
    Connor
    Feb 14, 2014
Loading...

Share This Page