搭建微博Cookies池(三)

调度模块

在完成存储、cookies获取、检测等模块后,我们需要一个调度模块将不同模块在不同进程上运行起来。
这里导入python自带多进程库 multiprocessing里的Process,注意这里Process要大写,有些IDE里自动补全为小写会报错
Process()的用法为:
def C():
print(‘我是C线程’)
a=Process(target=C)
a.start() #线程开始

scheduler.py

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()
    
        
        

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值