tt.py 698 B

12345678910111213141516171819202122232425
  1. import asyncio
  2. import time
  3. async def run(task_id, mode, platform):
  4. """
  5. 传入参数,然后根据参数执行爬虫代码
  6. :return: None
  7. """
  8. # 创建并等待一个子进程
  9. await asyncio.create_subprocess_shell("python3 scheduler/run_spider_online.py --task_id {} --mode {} --platform {}".format(task_id, mode, platform))
  10. async def main():
  11. # 创建爬虫task
  12. while True:
  13. for task_id in range(95, 96):
  14. print("start:{:02}, {}".format(task_id, int(time.time())))
  15. await asyncio.create_task(run(task_id, "recommend", "test"))
  16. time.sleep(1)
  17. if __name__ == '__main__':
  18. # 运行主事件循环
  19. asyncio.run(main())