I want to execute an executable of a Fortran code using python, with printing live output. I used subprocess.Popen
to see live output as shown here. I do get live output when I execute commands like 'du', however I get output for my Fortran's executable only after finishing its run.
Relevant part of my python script is:
import subprocess as s
a=s.Popen('./fortran_with_fft.exe', shell=True, stdout=s.PIPE)
for line in iter(a.stdout.readline, ''):
print line
When I run the executable from terminal, it runs without any error and producing the intended output. The same does not happen while running it from python. The Fortran code uses fftw to perform fft calculations using multiple threads. I use 16 threads for this. Relevant part of my Fortran code is:
nthreads=16
CALL sfftw_init_threads
CALL sfftw_plan_with_nthreads(nthreads)
CALL sfftw_plan_dft_3d(plan,ngrid,ngrid,ngrid,delta,delta,FFTW_BACKWARD,FFTW_estimate)
delta=CMPLX(densitycontr,0.0)
CALL sfftw_execute(plan)
I suspect that this problem of not printing live output is related with the fact that the executable uses multiple threads via fft. Is there any way to get live output for executing such processes which use multiple threads, through python?