t_process_mgr.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import asyncio
  2. from pathlib import Path
  3. import sys
  4. import time
  5. sys.path.append(str(Path(r'G:\code\upwork\zhang_crawl_bio\ui\backend')))
  6. from utils.process_mgr import ProcessManager
  7. from utils.logu import get_logger
  8. logger = get_logger('mytests', file=True)
  9. async def main():
  10. # 单例实例
  11. process_manager = ProcessManager()
  12. bin_path = r'G:\code\upwork\zhang_crawl_bio\download\proxy_pool\mihomo-windows-amd64-go120.exe'
  13. file1 = r'G:\code\upwork\zhang_crawl_bio\download\proxy_pool\yfjc_9361.yaml'
  14. file2 = r'G:\code\upwork\zhang_crawl_bio\download\proxy_pool\yfjc_9363.yaml'
  15. file3 = r'G:\code\upwork\zhang_crawl_bio\download\proxy_pool\yfjc_9365.yaml'
  16. file4 = r'G:\code\upwork\zhang_crawl_bio\download\proxy_pool\yfjc_9367.yaml'
  17. file5 = r'G:\code\upwork\zhang_crawl_bio\download\proxy_pool\yfjc_9369.yaml'
  18. list_files = [file1,file2,file3,file4,file5]
  19. for file in list_files:
  20. pid = await process_manager.start_process(f"mimo_{Path(file).stem}", [bin_path, '-f' ,file], )
  21. logger.info(f"start {pid}, file {file}")
  22. logger.info(f"processes {process_manager.processes}")
  23. try:
  24. while True:
  25. await asyncio.sleep(1)
  26. except KeyboardInterrupt:
  27. logger.info("KeyboardInterrupt")
  28. success = await process_manager.cleanup()
  29. if __name__ == "__main__":
  30. asyncio.run(main())