I'm trying to create a web extractor, I have this code for multithreads, and I need print the status/progress of the scanner :
import time
import threading
import Queue
import sys
try:
Lista = open(sys.argv[1], "r").readlines()
except(IOError):
print "Error: Check your ip list path\n"
sys.exit(1)
class WorkerThread(threading.Thread) :
def __init__(self, queue) :
threading.Thread.__init__(self)
self.queue = queue
def run(self) :
while True :
counter = self.queue.get()
sys.stdout.write("line nr : \r")
self.queue.task_done()
queue = Queue.Queue()
for i in range(50) :
worker = WorkerThread(queue)
worker.setDaemon(True)
worker.start()
for line in Lista:
queue.put(line)
queue.join()
print "All task over!"
How can I print the status/progress when the scanner working, I'm tried len(queue) but it doesn't work?
len(queue)is not correct?Queues don't have lengths, so you get aTypeErrororAttributeErrordepending on your Python version, and presumably he doesn't consider that a correct way to get information for a progress bar…