I have a script I'm writing to batch download images from an imageboard via JSON/XML api. Previously, it had been purely CLI, but recently I've been trying to build a UI in PyQt, with great success but for one problem: thread blocking issues, nonresponsive GUI when actually calling the worker threads within my script. So, I'm trying to switch from threading.Thread to QThread, to make it easier to manage (by emitting a threadFinished SIGNAL to update my GUI), but I can't seem to get it set up properly. Whenever I run the script, The threads die prematurely. I am running on windows, with PyQt4 on Python 2.7.2.

Qt Code:
  1. Exception KeyError: KeyError(1188,) in <module 'threading' from 'C:\Python27\lib
  2. \threading.pyc'> ignored
  3. QObject::killTimers: timers cannot be stopped from another thread
To copy to clipboard, switch view to plain text mode 

this is the output I receive.


Direct code in question:

in crawler.py:


Qt Code:
  1. ## md5_queue is queue of an empty dict of md5sum/filename to be filled by Url_Download()
  2. ## queue is a queue tuple of filenames/urls
  3. num_conn = int(max_threads)
  4. threads = []
  5. for download in range(num_conn):
  6. t = Url_Download(queue, md5_queue)
  7. t.start()
  8. threads.append(t)
To copy to clipboard, switch view to plain text mode 


from functions.py (poorly named, I know) the Url_Download() class:

Qt Code:
  1. class Url_Download(QThread):
  2.  
  3. file_finished = pyqtSignal(QString, int, name="fileFinished")
  4.  
  5. def __init__(self, dl_queue, md5_queue):
  6. self.dl_queue = dl_queue
  7. self.md5_queue = md5_queue
  8. QThread.__init__(self)
  9. def run(self):
  10. while 1:
  11. try:
  12. count = 0
  13. file_url, file_path, md5 = self.dl_queue.get_nowait()
  14. file_extension = str(file_url)[-4:]
  15. file_name = md5 + file_extension
  16. while count < 3:
  17. count +=1
  18. fetch_url(file_url, file_path, md5)
  19. if md5 == hash_sum(file_path):
  20. self.md5_queue.put_nowait((md5, file_name))
  21. self.file_finished.emit("Test!", 10)
  22. break
  23.  
  24. if count > 3:
  25. print 'File failed to download, {} might be corrupt.'.format(file_name)
  26. qsize = self.dl_queue.qsize()
  27. if qsize > 0:
  28. print 'Count Remaining: ', qsize
  29. except Queue.Empty:
  30. raise SystemExit
  31. except:
  32. traceback.print_exc(file=sys.stderr)
  33. sys.stderr.flush()
To copy to clipboard, switch view to plain text mode 


and from GUI.py, the slot connect:

Qt Code:
  1. self.connect(self, SIGNAL("fileFinished(QString, int)"), self.handle_test, Qt.QueuedConnection)
To copy to clipboard, switch view to plain text mode 





Git (testing branch) for the code: https://github.com/CirnoIsTheStronge...r/tree/testing

Please note, this is my first ever attempt at coding anything.