google tech talk code (threading module)

wiso gtu2003 at alice.it
Tue Sep 8 08:23:54 EDT 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):
        self.setDaemon(True)
        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/threading.py", line 522, in __bootstrap_inner
    self.run()
  File "wget_m.py", line 7, in run
    self.setDaemon(True)
  File "/usr/lib64/python2.6/threading.py", line 690, in setDaemon
    self.daemon = daemonic
  File "/usr/lib64/python2.6/threading.py", 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