import os import sys import time import schedule import multiprocessing sys.path.append(os.getcwd()) from scheduler import SpiderHome class SpiderScheduler(object): SH = SpiderHome() @classmethod def protect_spider_timeout(cls, function, hour): run_time_limit = hour * 3600 start_time = time.time() process = multiprocessing.Process(target=function) process.start() while True: if time.time() - start_time >= run_time_limit: process.terminate() break if not process.is_alive(): print("正在重启") process.terminate() time.sleep(60) os.system("adb forward --remove-all") process = multiprocessing.Process(target=function) process.start() time.sleep(60) @classmethod def run_xng_plus(cls, hour): cls.protect_spider_timeout(function=cls.SH.run_xng_plus, hour=hour) @classmethod def run_zhuFuQuanZi(cls): print("hello") @classmethod def run_spss(cls, hour): cls.protect_spider_timeout(function=cls.SH.run_spss, hour=hour) @classmethod def run_spss_id(cls, hour): cls.protect_spider_timeout(function=cls.SH.run_spss_id, hour=hour) if __name__ == "__main__": SC = SpiderScheduler() SC.run_spss(hour=5) # # schedule.every().day.at("20:06").do(SC.run_xng_plus, hour=1) # schedule.every().day.at("20:30").do(SC.run_spss, hour=1) # # schedule.every().day.at("18:30").do(SC.run_spss_id, hour=1) # # while True: # schedule.run_pending()