main.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import sys
  3. import time
  4. import schedule
  5. import multiprocessing
  6. sys.path.append(os.getcwd())
  7. from scheduler.spider_scheduler import SpiderHome
  8. class SpiderScheduler(object):
  9. SH = SpiderHome()
  10. @classmethod
  11. def protect_spider_timeout(cls, function, hour):
  12. run_time_limit = hour * 3600
  13. start_time = time.time()
  14. process = multiprocessing.Process(target=function)
  15. process.start()
  16. while True:
  17. if time.time() - start_time >= run_time_limit:
  18. process.terminate()
  19. break
  20. if not process.is_alive():
  21. print("正在重启")
  22. process.terminate()
  23. time.sleep(60)
  24. os.system("adb forward --remove-all")
  25. process = multiprocessing.Process(target=function)
  26. process.start()
  27. time.sleep(60)
  28. @classmethod
  29. def run_xng_plus(cls, hour):
  30. cls.protect_spider_timeout(function=cls.SH.run_xng_plus, hour=hour)
  31. @classmethod
  32. def run_zhuFuQuanZi(cls):
  33. print("hello")
  34. if __name__ == "__main__":
  35. SC = SpiderScheduler()
  36. schedule.every().day.at("14:30").do(SC.run_xng_plus, hour=1)
  37. while True:
  38. schedule.run_pending()