首页 > 解决方案 > Subprocess.check_output 进入挂起状态

问题描述

尽管 yaml 被执行并且执行完成了,python 代码仍然不会终止。

subprocess.check_output("nohup ansible-playbook ansible_final.yml -u ec2-user &",shell=True)

标签: python-3.xansible-2.x

解决方案


使用下面的代码

with open('error.err','w') as ferr, open('output.out','w') as fout:
                p=subprocess.Popen('ansible-playbook ansible_final.yml -u ec2-user &', stdout=fout, stderr=ferr,preexec_fn=os.setsid,shell=True)

推荐阅读