print() interrupted with rshell, resumes with repl

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
barn_rd
Posts: 1
Joined: Tue Jan 28, 2020 4:31 pm

print() interrupted with rshell, resumes with repl

Post by barn_rd » Tue Jan 28, 2020 6:59 pm

Hi Forum:

First time caller. Fairly new to Python. Warning! Portions of this are not very 'pythonic'.

The following psedo-code is structurally very similar to a program that I am writing.

Code: Select all

def Do_Weird_Stuff():
    print(' ');  #<- this is the interesting part
    return [51.60709 995.4415 237.2677 685.4344 36.96526 259.2582]

def Calc():
    while True
        bCals = Do_Weird_Stuff();
        if (bCals[0] == some_value):
             return bCalcs;

def main():
    print('main() - Start!')
    for i in range(3):
        LED_on();
        pyb.delay(500);
        bResult = Calc()
        print(bResult, ' Iteration: ', i);
        LED_off();
        pyb.delay(500);
        
print('Exiting...');
It iterates through a loop 3 times. It blinks the board LED, it calculates some stuff and prints the output of the calculations.

I expect the following output from the program:
main() - Start!
51.60709 995.4415 237.2677 685.4344 36.96526 259.2582 Iteration: 1
51.60709 995.4415 237.2677 685.4344 36.96526 259.2582 Iteration: 2
51.60709 995.4415 237.2677 685.4344 36.96526 259.2582 Iteration: 3
Exiting...

The program does not do that. It lists the following:
Part 1.
main() - Start!

Part 2.
---> At this point, the output from the program has stopped and lands at an rshell prompt.
---> So, I type in 'repl' on the rshell command line and get the following:

Part 3. The rest of the output displays.
51.60709 995.4415 237.2677 685.4344 36.96526 259.2582 Iteration: 1
51.60709 995.4415 237.2677 685.4344 36.96526 259.2582 Iteration: 2
51.60709 995.4415 237.2677 685.4344 36.96526 259.2582 Iteration: 3
Exiting...

There are two interesting things about this.
  • 1. The program exits very quickly to rshell; but, I can tell the program is still executing because the LED continues to blink.
    As soon as I run repl from the rshell command line, the rest of the output is displayed.
    I can not figure out why this happens.

    2. I can force a change in the behavior of the output if I put a print() statement in the Do_Weird_Stuff() routine.
    (See above) As soon as I put in the print() statement in Do_Weird_Stuff(), the program displays as expected; but,
    with an extra print().
I'd like to get all of the output at once without forcing an extra print() statement or having to run repl.
Any thoughts as to what is going on?

Thanks

User avatar
jimmo
Posts: 1845
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: print() interrupted with rshell, resumes with repl

Post by jimmo » Mon Feb 03, 2020 5:51 am

Hi,
barn_rd wrote:
Tue Jan 28, 2020 6:59 pm
The following psedo-code is structurally very similar to a program that I am writing.
I looked at this briefly and modified it enough to make it work, but couldn't make the same issue happen. It would be really good if you could come up with something that I can run here.

Does your code involve timers or callbacks?

How do you invoke the program from rshell? Can you copy and paste a sample session showing the bug?

Thanks

Post Reply