threading v thread

Greg & Janet LINDSTROM yuba at cyberback.com
Thu Dec 14 17:54:31 EST 2000


Greetings-

I have been coding full time for about 12 years; the last 5 or so have found me coding multi-threaded applications in C for a mid-sized (soon to be large:-) I.T. shop in Arkansas.  One of the bread-and-butter applications I oversee was written in C using sockets for IPC. The code is so obfuscated it is beyond belief so, just for fun, I took a couple of days and wrote the application in Python.  The C source code is approximately 90 pages (I can't be exact because I cannot tell, for certain, how much of this code is actually used in the application!); my python routine is 4 pages.  Better yet, I gave the code to a co-worker and asked him to make a modification in order to test whether or not the code was maintainable.  He had no problem with it.

One of the reasons I cannot convince my group to go with Python in "the speed" problem (the other two problems are Python is free and it's "not supported" :-).  Every knows that C/C++ is much faster than Python.  But in this case, my experimental code runs just a tad (about 5%) slower than the C code.  I feel that if I would take the time to optimize -- or rather, properly write -- the routine in C, it would probably run much faster, but it outruns the mid-tier now, and I like the idea of 4 pages of source code.

Though I wrote the application using thread because it matched the syntax of the thread models normally use, I would like to write it using the threads package.  I have not, however, been able to create a multi-threaded object (this is, perhaps due to my deficiencies in using objects; I am still, at heart, a C coder).  If any of you have a simple example of how to use the threads package, would you please send me a copy to I can plagiarize your work.  By simple, I mean (perhaps) an object that counts from A to B, where A and B are input parameters, or a routine that uses threads to find the first N primes.  PLEASE DO NOT sent me your 500 page masters thesis showing how to model PDEs!!

Also, in the threading vein: Does python take advantage of multiple processors on a single box?  My routine, when run on a DEC Alpha using DEC UNIX seems to balance the processors.  The same code run on NT appears to only "see" one of the processors (it's a 4 processor box).  Is this a "feature" of the OS.

Thanks!
Greg Lindstrom

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20001214/05987d42/attachment.html>


More information about the Python-list mailing list