python and multi-threaded C programs

Arvind Mani marvind at
Thu Feb 22 16:13:03 EST 2001


I saw your reply just now.

Well I am implementing a key managment and distribution protocol for dynamic
groups. I have one thread waiting for messages from the initiator who controls
just the group membership but does not take part in key formation after the
initial round, one thread sending/receiving messages from other group members,
one thread for the rekey signal (USR1) so that they can form the secret key
again, one thread to receive fractional keys from other members and to send
its own contribution to the shared key and finally one thread to start the
python script. This is on the host side. The initiator code is simpler and has
only 2 threads - gui and the other to receive messages indicating membership
changes, round nos., etc. I have finished as much.

This application will sit on top of a dynamic routing protocol, say TORA. The
user interface will be in Tkinter.

I have completed the first part and also extended certain functions so that
they could be called from python. I got stuck with globals that are used in
other threads.

And I have semaphores to enforce certain oredering of events and mutexes to
protect globals. I think all the above are possible using Python.

I would be very grateful if you could tell me if using python to do the above
is straightforward. Can you point me to a tutorial on creating, cancelling
threads in python.
I did not need much effort for the first part and so I can redo the whole


Bryan Mongeau wrote:

> Arvind Mani wrote:
> > Hi,
> >
> > I am new to python. I have a multi-threaded application in C. I would
> > like to create the threads in python and then use the thread routine
> > written in C. Is this possible?
> >
> > I am doing this because, I had some problems with global variables that
> > are initialized in one thread but used in another. I dont need these
> > variables to be directly visible to the python interpreter. They are
> > required in functions that I call from python.
> >
> >
> > Thanks,
> > Arvind
> >
> Arvind,
> I noticed your post over on the SWIG list. I can't help but wonder just how
> valuable those thread routines in C are to you... You would save yourself a
> great headache (not to mention maintainability nightmares) if you ported
> your socket routines to python. It's not hard you know. Plus you can wield
> python's super-powers :)
> Out of curiosity, are you making a distributed, decentralized file-sharing
> network? :)
> --
> <==================================>
> Bryan Mongeau
> Lead Developer, Director
> eEvolved Real-Time Technologies Inc.
> <==================================>
> "Scientific beliefs are supported by evidence, and they get results. Myths
> and faiths are not and do not" -- Richard Dawkins

More information about the Python-list mailing list