Threading with queues
Gib Bogle
g.bogle at auckland.no.spam.ac.nz
Mon Dec 21 18:47:12 EST 2009
Stephen Hansen wrote:
> 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
It turns out that this code isn't a great demo of the advantages of threading,
on my system anyway. The time taken to execute doesn't vary much when the
number of threads is set anywhere from 1 to 6.
More information about the Python-list
mailing list