multithreading - Queue Python threading (Segmentation fault: 11) -
i have queue set this. want run through items in db query , pass them downloader class. db connection keeps going away , program dies because think many threads open?
i error: segmentation fault: 11
there 100k+ items.
how can fix process few items @ time , speed process?
class downloader(threading.thread): """threaded file downloader""" def __init__(self, queue, db): threading.thread.__init__(self) self.queue = queue self.db = db def remove_unicode(self, title): try: return unicodedata.normalize('nfkd', title).encode('ascii','ignore') except: return title def run(self): while true: # gets url queue row = self.queue.get() title = row[0] etc... def main(urls): queue = queue.queue() # create thread pool , give them queue in range(5): t = downloader(queue, db) t.setdaemon(true) t.start() # give queue data = 1 url in urls: print queue.put(url) i+=1 # wait queue finish queue.join() if __name__ == "__main__": db = databaseutil() sql = 'select `title`, `site` `xyz`' titles = db.query(sql) main(titles)
Comments
Post a Comment