[CentralOH] Fwd: Re: Stackless Python

Brian Costlow brian.costlow at gmail.com
Wed Nov 4 20:50:22 CET 2009


Bryan,

Didn't see any public responses to your post of your code, wondered if you
got any private help?

I took a quick look at the code, and I am certain that the GIL issues are
what are slowing down your threaded version.

There's nothing you can do to code around that, the GIL keeps python from
running threaded code sanely in a multicore environment.

It's an implementation limitation of CPython.

You do need to add your lock around your 'done' print statement. The GIL is
removed for I/O and without the lock, these intermix with the worker
threads' print statements.

e.g.,

7 7.29473684211
7 7.21875
7 7.14432989691
 Thread number 7 1 7.07142857143
 is done7
 7.0
Thread number  27 6.93
 is done
Thread number  3 is done


for pingle in pinglist:
   pingle.join()
   with some_lock:
       print "Thread number ",pingle.number,"is done"


I noticed from your comments in the code that this was originally doing
pings. That's I/O bound and could be a case where threads would help in a
single-core setup. But after looking at David Beazley's talk, probably would
still behave badly on multiple cores.

However, for I/O bound code, as opposed to processor-bound, Stackless might
help.

Other possibilities would be Eventlet, Twisted, or rolling your own
asynchronous code using asyncore.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20091104/3e0b336f/attachment.htm>


More information about the CentralOH mailing list