subprocess.check_output 在脚本 python 上太慢了,但在交互式 python shell 上却不是
subprocess.check_output is too slow on script python but not in interactive python shell
我的问题是关于子流程的。
我正在使用子进程调用外部程序,我使用了 check_output() 方法,在该方法中我将 args 作为列表传递。我注意到的是,当从交互式 shell 使用 check_output() 时,它需要 3 分钟(在我的情况下这是执行外部程序的正确时间 [如果过程没有问题保持阻塞等待响应]) 但是,当我在 python 脚本中使用具有相同参数的相同方法时,它最多可能需要 1 小时!
有没有人遇到过这种情况?有什么建议吗?
有关信息,我在 Debian 10 上使用 Python3.7.3。
谢谢提前
---- 编辑:
我的代码没有什么特别之处
我的脚本是:
from subprocess import check_output
try:
#commandList is the programm (external bin) I would excute with its params
result = check_output(commandList)
print(result.decode("latin-1"))
except Exception as e:
print(e)
使用 subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess. STDOUT, shell=True)
解决了问题。
我的问题是关于子流程的。
我正在使用子进程调用外部程序,我使用了 check_output() 方法,在该方法中我将 args 作为列表传递。我注意到的是,当从交互式 shell 使用 check_output() 时,它需要 3 分钟(在我的情况下这是执行外部程序的正确时间 [如果过程没有问题保持阻塞等待响应]) 但是,当我在 python 脚本中使用具有相同参数的相同方法时,它最多可能需要 1 小时!
有没有人遇到过这种情况?有什么建议吗?
有关信息,我在 Debian 10 上使用 Python3.7.3。
谢谢提前
---- 编辑:
我的代码没有什么特别之处
我的脚本是:
from subprocess import check_output
try:
#commandList is the programm (external bin) I would excute with its params
result = check_output(commandList)
print(result.decode("latin-1"))
except Exception as e:
print(e)
使用 subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess. STDOUT, shell=True)
解决了问题。