I want to measure the time of execution of an external program whose output is used by my Python script.
Calling extprogram
the program that produced the output, at the moment I do something like:
import time
import subprocess
def process_output(line):
...
...
return processed_data
all_processed_data = []
ts = time.time()
p = subprocess.Popen("extprogram", stdout=subprocess.PIPE)
for line in p.stdout:
all_processed_data.append(process_output(line))
te = time.time()
elapsed_time = te - ts
This doesn't work as intended because what I am measuring is the time of execution of extprogram
plus the time required to process its output.
extprogram
produces a large amount of data, therefore I would like to "stream" its output in my Python program using a cycle as I am doing now.
How can I evaluate te
when extprogram
terminates rather than waiting for all the output to be processed?