-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
57 lines (50 loc) · 1.35 KB
/
run.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
# IP代理池-调度模块
API_HOST = 'localhost'
API_PORT = 5000
TESTER_CYCLE = 20
GETTER_CYCLE = 20
TESTER_ENABLED = True
GETTER_ENABLED = True
API_ENABLED = True
from multiprocessing import Process
from api import app
from getter import Getter
from tester import Tester
import time
class Scheduler():
def schedule_tester(self,cycle=TESTER_CYCLE):
'''
定时测试代理
'''
tester = Tester()
while True:
print('测试器开始执行')
tester.run()
time.sleep(cycle)
def schedule_getter(self,cycle=GETTER_CYCLE):
'''
定时获取代理
'''
getter = Getter()
while True:
print('开始抓取代理')
getter.run()
time.sleep(cycle)
def schedule_api(self):
'''
开启api
'''
app.run(API_HOST,API_PORT)
def run(self):
print('代理池开始运行')
if TESTER_ENABLED:
tester_process = Process(target=self.schedule_tester)
tester_process.start()
if GETTER_ENABLED:
getter_process = Process(target=self.schedule_getter)
getter_process.start()
if API_ENABLED:
api_process = Process(target=self.schedule_api)
api_process.start()
if __name__ == '__main__':
Scheduler().run()