-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.py
More file actions
42 lines (31 loc) · 1.11 KB
/
executor.py
File metadata and controls
42 lines (31 loc) · 1.11 KB
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
# -*- coding: utf8 -*-
# created by Jin(jinzhencheng@auto-smart.com) at 2017/09/18.
from validator import Validator
from logger import Logger
from db_helper import DBOperator
import time
import Queue
import config
logger = Logger(__name__, "proxy-validator.log").get_logger()
class Executor(object):
def __init__(self):
self.queue = Queue.Queue()
self.db_helper = DBOperator()
def __init_queue(self):
proxy_list = self.db_helper.query()
for proxy in proxy_list:
self.queue.put(proxy)
def execute(self):
for i in range(0, config.DEFAULT_VALIDATE_THREAD):
print i
validator = Validator("validator_%d" % i)
if self.queue.empty():
self.__init_queue()
logger.info("=== validator:%s has started, current queue size is: %d ===" % (i, self.queue.qsize()))
validator.queue = self.queue
validator.start()
time.sleep(config.DEFAULT_VALIDE_SLEEP)
logger.info("==== All thread have been executed. ===")
if __name__ == "__main__":
exe = Executor()
exe.execute()