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") if __name__ == "__main__": SC = SpiderScheduler() schedule.every().day.at("20:06").do(SC.run_xng_plus, hour=1) while True: schedule.run_pending()