Search code examples
pythongnuradiognuradio-companion

Printing from within an embedded Python program in GNU Radio Companion


I am using an embedded Python program to take an average of a large number of spectra in GNU radio Companion. I want to continuously print the number of averaged spectra so that output happens on a same line, always overwriting the previous number. So not printing each number on a separate line.

In Python you can do it in the following way:

for i in range(100000):
    print('Number of spectra averaged  ', i, end='\r')

However, that does not work from within an embedded Python program, each number is on its own line, which is very time consuming.

I thought that the escape character '\r' causes the problem, but probably not because the escape character '\n' works as it should be when printing from within a Python program.

I have tried all the tricks I have found for printing the output on a single line, but none of them works for an embedded Python program.

The printing from the embedded Python program goes both to the terminal where I started gnuradio-companion, and to the console of the gnuradio-companion. In both cases the printing produces several lines, not a single line which would be always overwritten.

How to print on a single line, overwriting the previous output ? I am using GRC 3.9.5.0 (Python 3.8.10) on Ubuntu 22.04.4

Cheers, Kimmo


Solution

  • Thanks Marcus

    Yes, I was referring to the 'mini-terminal' or 'log-terminal' in GRC.

    Using QT GUI Number Sink works fine. I just added one more output (of the type float because Number Sink cannot receive integer value inputs) to the Python block, and directed it to Number Sink.

    In the Number Sink I am using 'Update period = 0.5' because if using a value of zero the CPU load is increasing by about 10%