-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProxyUpdater.py
37 lines (30 loc) · 1.13 KB
/
ProxyUpdater.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
import threading
from Proxy import Proxy
class ProxyUpdater(threading.Thread):
def __init__(self, numberOfThreads):
self.numberOfThreads = numberOfThreads
super(ProxyUpdater, self).__init__()
def run(self):
# Create threads that will be constantly filled
print('ProxyUpdater started')
proxyList = []
threadsList = []
for i in range(self.numberOfThreads):
t = threading.Thread(target=ProxyUpdater._worker, args=(i, proxyList,))
threadsList.append(t)
t.start()
print('Thread ' + str(i) + ' started')
while True:
# Append more items to the list when needed
if len(proxyList) < 100:
print('100 more items added')
proxyList.extend(Proxy.getProxyBag(100))
@staticmethod
def _worker(threadNumber, proxyList):
while True:
try:
proxy = proxyList.pop(0)
proxy.updateProxy()
# print('Proxy ' + proxy.host + ':' + str(proxy.port) + ' updated by thread ' + str(threadNumber))
except:
pass