[英]python subprocess sub thread does not exit?
the following code is strange: 以下代码很奇怪:
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()
when i execute a complicate shell script, if i set the pipe is true: the err will be : A thread exited while 2 threads were running if i set pipe false the err will be : broken pipe 当我执行复杂的shell脚本时,如果我将管道设置为true:err将为:如果我将管道设置为false,则在运行2个线程时退出了一个线程,err将是:管道破裂
who can help me ? 谁能帮我 ? thanks 谢谢
You can use simplier os.popen() function. 您可以使用简单的os.popen()函数。 Example from my program: 我程序中的示例:
import os
manifest = os.popen("aapt dump badging " + apk).read() #running command
for info in manifest.splitlines():
... # extracting values
Also, subprocess module has a bug: if in subprocess.Popen() you specify non-ascii path, then error will occur. 此外,子进程模块有一个错误:如果在subprocess.Popen()中指定了非ASCII路径,则会发生错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.