I'm having a problem with the module subprocess; I'm running 开发者_如何学编程a script from Python:
subprocess.Popen('./run_pythia.sh', shell=True).communicate()
and sometimes it just blocks and it doesn't finish to execute the script. Before I was using .wait()
, but I switched to .communicate()
. Nevertheless the problem continues.
First the script compiles a few files, then it execute into a file:
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
Is the script you execute, is run_pythia.sh
guaranteed to finish executing? If not, you might not want to use blocking methods like communicate()
. You might want to look into interacting with the .stdout
, .stderr
, and .stdin
file handles of the returned process handle yourself (in a non-blocking manner).
Also, if you still want to use communicate()
, you need to have had passed subprocess.PIPE
object to Popen
's constructor arguments.
Read the documentation on the module for more details.
Maybe you can try to do a trace on it:
import pdb; pdb.set_trace()
精彩评论