/
server.py
46 lines (36 loc) · 1.04 KB
/
server.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
# coding: utf-8
# author: QCL
# software: PyCharm Professional Edition 2018.2.8
import time
import tornado.web
import tornado.ioloop
from loguru import logger
from checker.check import main
from application import Application
from multiprocessing import Process
from config import SERVER_PORT, TEST_PROXY_POOL_CYCLE
def test_proxy():
while True:
try:
main()
except AttributeError:
time.sleep(TEST_PROXY_POOL_CYCLE)
continue
time.sleep(TEST_PROXY_POOL_CYCLE)
def start_server():
app = Application()
logger.info(f'Listening on {SERVER_PORT}')
app.listen(SERVER_PORT)
tornado.ioloop.IOLoop.instance().start()
def run():
process_list = []
server_process = Process(target=start_server)
process_list.append(server_process)
server_process.start()
test_proxy_process = Process(target=test_proxy)
process_list.append(test_proxy_process)
test_proxy_process.start()
for process in process_list:
process.join()
if __name__ == '__main__':
run()