Skip to content

[Bug] using f'format strings in tight loop blocks and triggers watchdog timer #1668

@BertLindeman

Description

@BertLindeman

Describe the bug
Program is a tight loop printing f-strings. Within seconds the hub does a shutdown (somehow)
The display animation is no longer smooth but has large hickups.

Might this be related to #436 ?

To reproduce
Steps to reproduce the behavior:

  • connect the hub to USB for power
  1. Running in code.pybricks.com or beta
  2. Current setup is RobotInventor at 3.5.0 and SpikePrime at build 3380 (BT-button change)
  3. connect to the hub
  4. start the program (see below) via the app or website
  5. stop the program via the app and disconnect the hub
  6. stop the program by long-press on the hub button
  7. start the hub and run the program again (button press) but do not connect to the app
  8. a bit of patience (seconds) and see the hub goes OFF

Aditional info
Connected the hub before the test to USB to keep the power on.
After the crash connect to the hub and go to the REPL.
Showed:

>>> hub.system.reset_reason()
2
>>> 

Expected behavior
You'd expect the program to just keep running and not to power-off.

Screenshots
There is a saying that a picture is worth a 1000 words. Screenshots really help to identify and solve problems.

test program for this issue
# issues try_movehub_on_prime_6
# start this and while running disconnect with the app
# stop the hub to save the current program
# restart the hub (if build 3380 installed press the BT button -> red)
# start the program with the button, and
# within seconds the running square stops and the hub shutsdown


from pybricks.hubs import PrimeHub
from pybricks.tools import wait

HUB = PrimeHub()

# Initialize variables.
color_list = ["", "", "", "", "", "", ""]

_rand = HUB.battery.current() + HUB.battery.voltage()
# _rand = 123
INDEX = 4
A = 0
B = 5


def main2():
    while True:
        print(f'pre _rand {_rand:>5} A {A:>2} B {B:>2}', end=" ")
        print(f'_rand {_rand:>5} A {A:>2} B {B:>2}')
        print(f'INDEX {INDEX:>3} color_list[{INDEX}] {color_list[INDEX]}')
        # wait(1)  # with 1ms second wait: no problem
        wait(0.75)  # this wait is not enough to prevent the error


main2()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions