-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathengine.py
71 lines (58 loc) · 1.4 KB
/
engine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# encoding: utf-8
# @Author : w2n1ck
# @Time : 2018/3/11 下午6:35
# @Introduce : 线程引擎池
from gevent import monkey, pool
monkey.patch_all()
from wooyun import download2parser
import Queue
import threading
import time
exitFlag = 0
class myThread (threading.Thread):
def __init__(self, bugurl, q):
threading.Thread.__init__(self)
self.bugurl = bugurl
self.q = q
def run(self):
print "Starting " + self.bugurl
process_data(self.bugurl, self.q)
print "Exiting " + self.bugurl
def process_data(bugurl,q):
while not exitFlag:
queueLock.acquire()
if not workQueue.empty():
data = q.get()
download2parser(data)
queueLock.release()
else:
queueLock.release()
time.sleep(0.1)
queueLock = threading.Lock()
workQueue = Queue.Queue(100)
threads = []
'''
# 填充队列
queueLock.acquire()
for word in nameList:
workQueue.put(word)
queueLock.release()
'''
with open('./url-1.txt','r') as f:
bugurl = f.readlines()
queueLock.acquire()
for _ in bugurl:
workQueue.put(_)
thread = myThread(_)
thread.start()
threads.append(thread)
queueLock.release()
# 通知线程是时候退出
exitFlag = 1
# 等待所有线程完成
for t in threads:
t.join()
# 等待队列清空
while not workQueue.empty():
pass