Threading with queues

Stephen Hansen apt.shansen at gmail.com
Mon Dec 21 18:24:27 EST 2009


On Mon, Dec 21, 2009 at 3:12 PM, Gib Bogle
<g.bogle at auckland.no.spam.ac.nz> wrote:
>  #spawn a pool of threads, and pass them queue instance
>  for i in range(5):
>    t = ThreadUrl(queue,i)
>    t.setDaemon(True)
>    t.start()
>
>  #populate queue with data
>    for host in hosts:
>      queue.put(host)

This is indented over one indentation level too much. You want it to
be at the same level as the for above. Here, its at the same level
with "t" -- meaning this entire loop gets repeated five times.

I sorta really recommend a tab width of 4 spaces, not 2 :) At 2, its
_really_ hard (especially if you're newer to Python) to see these
kinds of issues and since indentation is program logic and structure
in Python, that's bad... especially since your comment is indented to
the right level, but the code isn't :)

--S



More information about the Python-list mailing list