Example of handling C callbacks

Mark Wilson m.wilson at bibliocraft.com
Fri Jan 5 07:38:55 EST 2001


Le

>Le Snelson <le_snelson at transtechinc.cc> wrote:
>I have a legacy system which uses an interprocess
communications (IPC)
>library. It behaves very much like X-windows.  It has its
own event loop
>and invokes callbacks in the same manner.
>
>What I would like to do is replace one of the processes in
the middle of
>this network of processes with a Python application.  So,
I'm looking
>for examples of how to handle C callbacks in extensions.
One thought
>I've had is to SWIG the libray interfaces.  This seems fine
for sending
>messages, but I can't visualize the callback
implementation.

Sounds like you need to check out PyEval_CallObject() etc.
Take a look at the Python docs "Extending Python with C or
C++>1.6 Calling Python Functions from C" (I'm looking at the
1.6 docs here - hope its not moved for 2.0). It may also be
worth taking a look at the book "Programming Python" by Mark
Lutz - quite old now, but fairly extensive discussion of
this kind of thing, plus some useful sample code.

Hope that helps.

Mark






More information about the Python-list mailing list