google tech talk code (threading module)

wiso gtu2003 at
Tue Sep 8 14:23:54 CEST 2009

I took a little code from google tech talk. It seems interesting, but it 
doesn't work:

import sys, urllib, os, threading, Queue

q = Queue.Queue()

class RetrWorker(threading.Thread):
    def run(self):
        def hook(*a): print (fn,a)
        while True:
            url = q.get()
            fn = os.path.basename(url)
            print url, "->", fn
            urllib.urlretrive(url, fn, hook)

for i in range(10): RetrWorker().start()
for url in sys.argv[1:]: q.put(url)

Exception in thread Thread-10:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/", line 522, in __bootstrap_inner
  File "", line 7, in run
  File "/usr/lib64/python2.6/", line 690, in setDaemon
    self.daemon = daemonic
  File "/usr/lib64/python2.6/", line 683, in daemon
    raise RuntimeError("cannot set daemon status of active thread");
RuntimeError: cannot set daemon status of active thread

More information about the Python-list mailing list