通过subprocess.Popen.poll 来控制流程

  • 分类: Python
  • 发表日期:2021-08-16 15:28:00
  • 最后修改:2021-08-16 15:28:00

开发中有时需要等待运行结果才能开始下一步,可以考虑使用subprocess模块来判断进程结果。

subprocess中的poll函数返回码:

  • 0 正常结束
  • 1 sleep
  • 2 子进程不存在
  • 5 kill
  • None 在运行

示例:

import subprocess

proc = subprocess.Popen(['python', 'test.py'], stdout=subprocess.PIPE)

while 1:
    if proc.poll() is None:
        break
    else:
        time.sleep(1)

 

post
2021年7月9日 09:40 原创 草稿

针对情报平台的多种 es dsl 测试

post
2021年7月13日 09:36 原创
post
2021年7月30日 12:01 原创
post
2021年7月30日 12:15 原创
post
2021年7月30日 15:07 原创
post
2021年7月30日 15:13 原创
post
2021年7月30日 15:18 原创
post
2021年7月30日 15:24 原创
post
2021年7月30日 16:09 原创
post
2021年7月30日 16:02 原创
post
2021年8月16日 20:01
post
2021年8月17日 12:07 原创
post
2021年8月31日 15:42 原创
post
2021年10月8日 16:17
post
2021年10月13日 11:43
post
2021年10月21日 15:47 原创
post
2021年10月25日 11:27

0 评论

大哥整点话呗~