Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13274

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

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: stackoverflow and c.l.py (was: GIL switch interval)
Date 2011-09-14 09:42 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-CE7C67.09425514092011@news.panix.com> (permalink)
References <CAB4yi1Nc04-6zw98WW+rss9u80amNbmk7GpMw-b0uHDdiRgC7w@mail.gmail.com> <mailman.1100.1315973589.27778.python-list@python.org> <Xns9F605E618E6B1duncanbooth@127.0.0.1>

Show all headers | View raw


In article <Xns9F605E618E6B1duncanbooth@127.0.0.1>,
 Duncan Booth <duncan.booth@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@python.org>,
 Stefan Behnel <stefan_ml@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

stackoverflow and c.l.py (was: GIL switch interval) Stefan Behnel <stefan_ml@behnel.de> - 2011-09-14 06:12 +0200
  Re: stackoverflow and c.l.py (was: GIL switch interval) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-14 15:35 +1000
    Re: stackoverflow and c.l.py Ethan Furman <ethan@stoneleaf.us> - 2011-09-13 23:47 -0700
  Re: stackoverflow and c.l.py (was: GIL switch interval) Duncan Booth <duncan.booth@invalid.invalid> - 2011-09-14 08:24 +0000
    Re: stackoverflow and c.l.py (was: GIL switch interval) Roy Smith <roy@panix.com> - 2011-09-14 09:42 -0400
      Re: stackoverflow and c.l.py (was: GIL switch interval) Duncan Booth <duncan.booth@invalid.invalid> - 2011-09-14 19:00 +0000
        Re: stackoverflow and c.l.py Thomas Jollans <t@jollybox.de> - 2011-09-14 21:34 +0200

csiph-web