Advice: socket handling and threads

Diez B. Roggisch nospam-deets at web.de
Wed Feb 4 11:11:03 EST 2004


> Is it sensible to port these sections of code to Python? Do I stand to
> gain or lose by doing this... I doubt the performance difference will be
> noticeable, and the only areas of the project that I would maybe consider
> extending in C++ are to do with parsing (and to be honest I think it'll be
> fine left in Python).
> 
> Finally there is the cherry on the cake in the form of cross-platform
> compatibility. My C++ code only works on *nix (or cygwin) but as far as I
> understand it, my threads and sockets should work fine on Windows and Mac
> too, if done in Python...? (This is a CLI app not GUI by the way.)
> 
> Thoughts and general musings will be greatly appreciated (as will any
> warnings of pitfalls I may encounter!)

You should look into python twisted, a framework for networking. It has
plenty of features. You can easily write portable networking code that
makes use of select for dispatching, so you don't need to be multithreaded.
It also supports reactors that are multithreaded, but in my expirience
thats not necessary, as multithreading often is an excuse for easier
handling of blocking io - which you avoid by the underlying select-based
infrastructure.

I had a mult-threaded client-server-app that also involved the serial line -
porting it to twisted was easy and straighforward, and now I'm rid of all
threads - which leads to way lower system load while the performance is the
same.

Regards,

Diez



More information about the Python-list mailing list