凉城旧巷
Python从入门到自闭,Java从自闭到放弃,数据库从删库到跑路,Linux从rm -rf到完犊子!!!

subprocess中的return_code与poll

p = subprocess.Popen('ping 8.8.8.8', shell=True, stdout=subprocess.PIPE, stderror=subprocess.DEVNULL)

while not p.poll():    # p.poll() 即为 return_code
    print(p.stdout.read().decode())

# return_code = p.poll()
# return_code = p.wait()
  • 0: 正常结束
  • 1 :sleep
  • 2:子进程不存在
  • <0:kill
  • None:正在运行

posted on 2024-02-21 15:34  凉城旧巷  阅读(58)  评论(0编辑  收藏  举报