stackoverflow and c.l.py (was: GIL switch interval)

Roy Smith roy at panix.com
Wed Sep 14 09:42:55 EDT 2011


In article <Xns9F605E618E6B1duncanbooth at 127.0.0.1>,
 Duncan Booth <duncan.booth at invalid.invalid> wrote:

> If you want an answer to how to get a specific bit of code to work then 
> Stackoverflow is better if only because people can see who has already 
> answered so don't need to waste time re-answering every trivial little 
> question about syntax.

Any halfway decent newsreader application will follow threading and put 
all the responses to a given question in one place.  Of course, this is 
a relatively new feature.  If your newsreader is any older than about 
the mid 1980's, it may not be able to do this.

In article <mailman.1100.1315973589.27778.python-list at python.org>,
 Stefan Behnel <stefan_ml at behnel.de> wrote:

> I wonder why people ask this kind of question on stackoverflow, and then 
> come here asking people to go over there, read the question, and 
> (potentially) provide an answer.

If you ask here you will probably get the correct answer to your 
question (along with some deep dives into related topics, which are 
often more valuable than the original answer).  If you ask on SO, you 
may also get the correct answer, but in addition you will earn SO karma 
points.  Maybe even some neat badge.  I guess it all depends on what 
your goal is.

Obligatory GIL comment -- I wrote some code the other day that used 4 
threads to perform 4 I/O bound operations (fetching 4 jpegs in parallel 
over http).  I figured the fact that they were I/O bound would avoid any 
GIL problems.  I was shocked and dismayed, however, to find that the 4 
operations all got serialized.  I guess I really didn't understand how 
the GIL worked after all.

So, I rewrote it to use the multiprocessing module.  Egads, still 
serialized!  To make a long story short, it turns out we were using some 
crappy consumer-grade Linksys box as our DNS server, and *it* was single 
threaded.  My 4 threads were blocking on name resolution!

We moved to using a real nameserver, and I converted the code back to 
using threading.  Works like a charm now.



More information about the Python-list mailing list