我的模块子进程有问题;我正在从 Python 运行脚本:
subprocess.Popen('./run_pythia.sh', shell=True).communicate()
有时它只是阻塞并且没有完成执行脚本。在我使用 .wait()
之前,但我 switched to .communicate()
。尽管如此,问题仍然存在。
首先脚本编译一些文件,然后执行到一个文件中:
run_pythia.sh
:
#!/bin/bash
#PBS -l walltime=1:00:00
./compile.sh
./exec > resultado.txt
compile.sh
:
O=`find ./ -name "*.o" | xargs`
# LOAD cernlib2005
module load libs/cernlib/2005
# Compile and Link
FC=g77
CERNLIBPATH="-L/software/local/cernlib/2005/lib -lpacklib"
$FC call_pyth_mix.f analise_tt.f $O $CERNLIBPATH -o exec
最佳答案
您执行的脚本是否能保证run_pythia.sh
完成执行?如果没有,您可能不想使用诸如 communicate()
之类的阻塞方法。您可能想研究一下与返回的进程句柄的 .stdout
、.stderr
和 .stdin
文件句柄进行交互(在非阻塞方式)。
此外,如果您仍然想使用 communicate()
,您需要将 subprocess.PIPE
对象传递给 Popen
的构造函数参数。
阅读documentation在模块上了解更多详细信息。
关于Python 子进程 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2769694/