I have a project in which I am using subprocess to call a C program and read an output. It takes 11.5 sec to return from the output request. The time is very consistent regardless of the size of the output or the complexity of parameters passed to the actual subprocess being used. Where is this HUGE delay coming from?
The following code is a test of this problem. You can see the times involved in the output printout.
import time, sys
timer = time.perf_counter if sys.platform[:3] == 'win' else time.time
start = timer() # Start timer reference here
# *** part of script that you would like to measure latency ****
elapsed = timer() - start # Measure elapsed time here
print('Elapsed time is: ', elapsed)
There is no need for either the str or float conversion. It provides the net elapsed time.
From your test results, it appears that the ft8_decode.stdout.read() is the line that is causing the issue. Can you test it with this code as a double verification?
start = timer() # Start timer reference here
output = ft8_decode.stdout.read()
elapsed = timer() - start # Measure elapsed time here
Your C code is so simple. Is there a special reason why you are including all of these libraries? For testing purposes, can you comment them out (maybe except for stdio).
Also, for this test, don’t use (comment out) your now / print pairs.
The extra includes were left over from my original file before I cut everything down to a test file. I commented out all except stdio. Also commented out the now/print pairs in test.py. The elapsed time is 11.50.
Here is something extra that might help. I am using the Geany IDE. There are 2 executable processes to use - Build and Make. When I do a Build, the code runs properly - no delay. When I run Make, the delay is present.
The Build line is:
gcc -Wall -o “test” “test.c”
The Make process is:
cc -03 -ggdb3 -fsanitize=address -std=c11 -I. -c -o test.o test.c
cc -lm -fsanitize=address -Wall -o test test.o
The Makefile I am using is a distillation of a Makefile used for the original project. Could this Make be the issue?
Your script is very small … just a handful of lines. Can you try running it from IDLE? Is the delay being generated by the Geany IDE?
@barry-scott showed that he does not get the delay that you are experiencing when he performs the test. Can you replicate his environment / test set-up?
Yes, this is correct. But what we are attempting to do here is to isolate / locate the source of the delay. Is it an IDE issue, maybe v3.11 issue, we don’t yet know.
I ran your code and I still get the delay. So I generated the executable on the command line - it works. This would seem to point to some bizarre issue with Geany. Or a linker issue. Maybe it is an issue with bookworm,