[英]python subprocess sub thread does not exit?
以下代码很奇怪:
def exec_shell(args, pipe = True):
pre_fun = None
if pipe == True:
pre_fun = lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL)
process = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
preexec_fn = pre_fun)
(out, err) = process.communicate()
当我执行复杂的shell脚本时,如果我将管道设置为true:err将为:如果我将管道设置为false,则在运行2个线程时退出了一个线程,err将是:管道破裂
谁能帮我 ? 谢谢
您可以使用简单的os.popen()函数。 我程序中的示例:
import os
manifest = os.popen("aapt dump badging " + apk).read() #running command
for info in manifest.splitlines():
... # extracting values
此外,子进程模块有一个错误:如果在subprocess.Popen()中指定了非ASCII路径,则会发生错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.