我正在尝试创建一个网络提取器,我有这个多线程代码,我需要打印扫描仪的状态/进度:
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!"
扫描仪工作时如何打印状态/进度,我试过len(queue)
但它不起作用?