[Python] Python subprocess.run running far too long [closed]

Discussão em 'Python' iniciado por Stack, Janeiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    The following code is part of a much larger project but is all that needs to be shown to illustrate my issue.

    In response to a request for more specific code to illustrate the issue I have provided the following information. I run the python code in a terminal. The test.c runs in ms. But you can see from the time shown that subprocess does not return for 12.6 seconds.

    What is subprocess.run doing for 12.6 seconds and how do I get rid of this delay?

    And here is the interesting part. I am using Geany for the editor and build software. If I build test.c, the code runs without a delay. If I make test.c the 12.6 second delay is present.

    Note that any type of file can be passed from the command arguments. I will let you substitute any file you wish.

    test.py:

    import time
    import subprocess
    from datetime import datetime

    cmd_args = ['/home/wa4ywm/gr-ft8_rxtx/Test/test', '/home/wa4ywm/ gr-ft8_rxtx/python/Hello.txt']

    now = float(datetime.now().strftime('%S.%f'))
    print ("Before ft8_decode = ", now)
    ft8_decode = subprocess.Popen(cmd_args, stdout=subprocess.PIPE)
    output, _ = ft8_decode.communicate()
    print(output.decode())

    now = float(datetime.now().strftime('%S.%f'))
    print ("After ft8_decode = ", now)


    Here is typical output showing the times of execution:

    wa4ywm@raspberrypi:~/gr-ft8_rxtx/Test $ python3 test.py
    Before ft8_decode = 24.282739

    After ft8_decode = Sun Jan 19 13:52:25 2025


    After ft8_decode = 36.900071


    test.c:

    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    #include <math.h>
    #include <stdbool.h>
    #include <time.h>

    int main(int argc, char **argv)
    {
    printf("Time4 before load_wav = \n");
    return 0;
    }


    The following Makefile is adapted from the file used for the larger project.

    Makefile:

    CFLAGS = -O3 -ggdb3 -fsanitize=address
    CPPFLAGS = -std=c11 -I.
    LDFLAGS = -lm -fsanitize=address -static-libasan

    TARGETS = test

    .PHONY: run_tests all clean

    all: $(TARGETS)

    run_tests: test
    @./test

    test: test.o fft/kiss_fftr.o fft/kiss_fft.o ft8/decode.o ft8/encode.o ft8/crc.o ft8/ldpc.o ft8/unpack.o ft8/text.o ft8/constants.o common/wave.o
    $(CXX) $(LDFLAGS) -o $@ $^

    clean:
    rm -f *.o ft8/*.o common/*.o fft/*.o $(TARGETS)
    install:
    $(AR) rc libft8.a ft8/constants.o ft8/encode.o ft8/pack.o ft8/text.o common/wave.o
    install libft8.a /usr/lib/libft8.a


    I have realized that this issue arose after a software update to my operating system and a GNU Radio update. I am running on a Raspberry Pi and the OS was updated to bookworm. GNU Radio was updated to 3.10 which included an update to Python 3.11.

    Any comments?

    Continue reading...

Compartilhe esta Página