off_line_controler.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import os
  2. import sys
  3. import time
  4. import schedule
  5. import multiprocessing
  6. sys.path.append(os.getcwd())
  7. from 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. @classmethod
  35. def run_spss(cls, hour):
  36. cls.protect_spider_timeout(function=cls.SH.run_spss, hour=hour)
  37. @classmethod
  38. def run_spss_id(cls, hour):
  39. cls.protect_spider_timeout(function=cls.SH.run_spss_id, hour=hour)
  40. if __name__ == "__main__":
  41. SC = SpiderScheduler()
  42. SC.run_spss(hour=5)
  43. # # schedule.every().day.at("20:06").do(SC.run_xng_plus, hour=1)
  44. # schedule.every().day.at("20:30").do(SC.run_spss, hour=1)
  45. #
  46. # schedule.every().day.at("18:30").do(SC.run_spss_id, hour=1)
  47. #
  48. # while True:
  49. # schedule.run_pending()