调度模块
在完成存储、cookies获取、检测等模块后,我们需要一个调度模块将不同模块在不同进程上运行起来。
这里导入python自带多进程库 multiprocessing里的Process,注意这里Process要大写,有些IDE里自动补全为小写会报错。
Process()的用法为:
def C():
print(‘我是C线程’)
a=Process(target=C)
a.start() #线程开始
from multiprocessing import Process
from api import app
from test import *
from new_cookies import *
from config import *
import time
class Schelduler():
@staticmethod
def test_cookies(cycle=60):
while True:
print('开始检测Cookies')
try:
for website,cls in TESTER_MAP.items():
test=eval(cls+'()')
test.run()
print('检测完成')
del test
time.sleep(cycle)
except Exception as e:
print(e.args,'\n--------------------------------\n')
time.sleep(cycle)
@staticmethod
def api():
print('api接口开始运行')
app.run(host=API_HOST,port=API_PORT)
def run(self):
if API_PROCESS:
api_process=Process(target=Schelduler.api)
api_process.start()
if TEST_PROCESS:
test_process=Process(target=Schelduler.test_cookies)
test_process.start()
if __name__ == '__main__':
zouni=Schelduler()
zouni.run()