You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Primehub "hangs" in mid program run on Pybricks beta.12 and firmware 3.0.0b4 #297
Describe the bug
Sometimes (unpredictable for me at the moment) a running program hangs
To reproduce
Steps to reproduce the behavior (NO fixed scenario, just sometimes)
Describing the last situation I had:
Go to code.pybricks.com
loaded and ran all tests in pybricks-micropython\tests\pup\sensors (a few times even)
except ultrasonic_presence.py
After starting ultrasonic_presence.py the situation occurred.
It is such a small program, I do not understand what's wrong.
Expected behavior
The test to run successfully
Screenshots Stationery so no animation, display looks like:
versions
Hub firmware: 'primehub', '3.0.0b4', 'b4b450d3 on 2021-04-10'
Pybricks protocol version: 1.0.0
Pybricks Code v1.0.0-beta.12
Win10
Microsoft Edge Versie 89.0.774.75 (Officiële build) (64-bits)
additional info
Stop button on the code webpage does "nothing"
attempt to stop the hub by holding the middle button, no success
have to take the battery out to get it back to normal.
No errors are seen on the developers' info page
There is a color sensor connected to the hardware module (1) during the hang the color sensor's lights blink altogether. looks like "half a second" OFF and "2 or 3 seconds" ON. The color sensor is not instantiated in the program.
The program
# SPDX-License-Identifier: MIT
# Copyright (c) 2020 The Pybricks Authors
"""
Hardware Module: 1
Description: Verifies that the Ultrasonic Sensor does not sense ultrasonic
interference by default.
"""
from pybricks.pupdevices import UltrasonicSensor
from pybricks.parameters import Port
# Initialize devices.
ultrasonic_sensor = UltrasonicSensor(Port.C)
# Assert that there are no ultrasonic devices nearby.
assert not ultrasonic_sensor.presence(), "Unexpected interference detected."
The same happened on Linux Google Chrome and Chromium after some more time.
After win10 reboot it takes a lot more time. (Not happened yet after 17,030,000 times taking sensor.distance()
Did not (yet) try.
And at the moment on Win10 (after reboot) no problem after 91,155,000 times taking the distance.
Might be "reboot" a first response?
Will try a technic hub now.
[EDIT] added program used:
frompybricks.pupdevicesimportUltrasonicSensorfrompybricks.parametersimportPortfrompybricks.toolsimportwait# Initialize the sensor.eyes=UltrasonicSensor(Port.C)
counter=0max=0min=9999whileTrue:
counter+=1# Print the measured distance.dist=eyes.distance()
ifdist>max:
max=distifdist<min:
min=distifcounter%5000==0:
print("%12d Distance:%5d Min:%5d Max:%5d"% (counter, dist, min, max))
max=0min=9999# # If an object is detected closer than 500mm:# if eyes.distance() < 500:# # Turn the lights on.# eyes.lights.on(100)# else:# # Turn the lights off.# eyes.lights.off()# Wait some time so we can read what is printed.# wait(100)
There have been quite a few times recently where I had to reboot Windows because it seems that the Bluetooth stack got in a bad state (i.e. restarting the web browser was not enough).
My feeling is that it is more than the Bluetooth stack.
It's confusing to me anyway.
The blinking colorsensor and no responsive middle button might not be caused by a Bluetooth stack on windows.
Win10 - MS EDGE test on TechnicHub is running - just passed the 10.000.000 mark.
Stopped the run on win10 at 54,060,000
Now back to linux mint.
got a "hang" after reboot win10
using MS EDGE on a Spike hub with firmware ('primehub', '3.0.0b5', 'e5858276 on 2021-04-12')
and Pybricks Code v1.0.0-beta.14
Maybe it's getting reproducible.
Run these test in pybricks-micropython\tests\pup\sensors THREE times in this order:
color_color.py
color_mode.py
color_reflection.py
ultrasonic_distance.py
Then running ultrasonic_lights.py causes the "hang".
This is the second time this occurred, now.
The scenario from above :
Run these test in pybricks-micropython\tests\pup\sensors THREE times in this order:
color_color.py
color_mode.py
color_reflection.py
ultrasonic_distance.py
Then running ultrasonic_lights.py causes the "hang".
Could be that there is a shorter recreate scenario, but this scenario now worked a number of times.
Will try to get it shorter and still produce the freeze each time.
Adapted ultrasonic_lights.py to run 'forever" like this:
# SPDX-License-Identifier: MIT# Copyright (c) 2020 The Pybricks Authors"""Hardware Module: 1Description: This tests the lights on the Ultrasonic Sensor. No externalsensors are used to verify that it works."""frompybricks.pupdevicesimportUltrasonicSensorfrompybricks.parametersimportPortfrompybricks.toolsimportwaitfromurandomimportrandint# Initialize devices.lights=UltrasonicSensor(Port.C).lightscount=0whileTrue:
count+=1print("Start iteration", count)
# Turn on all lights at full brightness.lights.on()
wait(500)
# Turn on all lights.foriinrange(-50, 150, 2):
lights.on(i)
wait(20)
# Turn of all lights.lights.off()
wait(500)
# Turn on all lights.foriinrange(50):
lights.on([randint(0, 100) forjinrange(4)])
wait(50)
Activity
BertLindeman commentedon Apr 11, 2021
Was busy on coverage test for Spike ColorSensor
BertLindeman commentedon Apr 11, 2021
After a reboot of the primehub, and ctrl-F5 on the code webpage:
ran ultrasonic_presence.py 93 times (counted on the log)
and then got:
BertLindeman commentedon Apr 11, 2021
Once more same hang; running:
pybricks-api\examples\pup\sensor_ultrasonic\basics.pySame hardware / software / environment.
Same blinking color sensor
[EDIT]: Does not seem to be memory-related.
Added to the loop:
Log at the start shows:
Log at the end shows:
BertLindeman commentedon Apr 11, 2021
The same happened on Linux Google Chrome and Chromium after some more time.
After win10 reboot it takes a lot more time. (Not happened yet after 17,030,000 times taking sensor.distance()
dlech commentedon Apr 11, 2021
Does this happen on other hubs?
BertLindeman commentedon Apr 11, 2021
Did not (yet) try.
And at the moment on Win10 (after reboot) no problem after 91,155,000 times taking the distance.
Might be "reboot" a first response?
Will try a technic hub now.
[EDIT] added program used:
dlech commentedon Apr 11, 2021
There have been quite a few times recently where I had to reboot Windows because it seems that the Bluetooth stack got in a bad state (i.e. restarting the web browser was not enough).
BertLindeman commentedon Apr 11, 2021
My feeling is that it is more than the Bluetooth stack.
It's confusing to me anyway.
The blinking colorsensor and no responsive middle button might not be caused by a Bluetooth stack on windows.
Win10 - MS EDGE test on TechnicHub is running - just passed the 10.000.000 mark.
Stopped the run on win10 at 54,060,000
Now back to linux mint.
BertLindeman commentedon Apr 12, 2021
got a "hang" after reboot win10
using MS EDGE on a Spike hub with firmware
('primehub', '3.0.0b5', 'e5858276 on 2021-04-12')and
Pybricks Code v1.0.0-beta.14Maybe it's getting reproducible.
Run these test in pybricks-micropython\tests\pup\sensors THREE times in this order:
Then running
ultrasonic_lights.pycauses the "hang".This is the second time this occurred, now.
Will try the same on Linux Mint tomorrow.
dlech commentedon Apr 12, 2021
Since
Pybricks Code v1.0.0-beta.14, if the hub hangs, can you reboot the hub and still use Pybricks Code without restarting Pybricks Code?BertLindeman commentedon Apr 13, 2021
Could not reboot by long-press the middle button. (did I forget a reboot button combination?)
Did:
no problem so far
Was that what you asked @dlech ?.
Could recreate the freeze on beta-14 on:
The scenario from above :
Run these test in pybricks-micropython\tests\pup\sensors THREE times in this order:
Then running
ultrasonic_lights.pycauses the "hang".Could be that there is a shorter recreate scenario, but this scenario now worked a number of times.
Will try to get it shorter and still produce the freeze each time.
BertLindeman commentedon Apr 13, 2021
Adapted
ultrasonic_lights.pyto run 'forever" like this:Ran a three times with this as result:
Each time eventually a freeze occurred.
So in iteration 4, 7 and 16
Not very stable though.
laurensvalk commentedon Apr 13, 2021
Thanks a lot for your detailed investigation!
I have a hunch that switching modes and writing to the sensor (for the lights) is wreaking havoc here.
BertLindeman commentedon Apr 13, 2021
@laurensvalk
A shorter script also does the freeze, but not as fast:
This does no mode switching, just write light values to the sensor.
Hang at:
Note that I removed the wait after the lights switch for speed sake
laurensvalk commentedon Apr 13, 2021
Indeed, both can be an issue, separately and combined. I'll add a test that does this specifically, thanks.
And just to confirm, you no longer see this, right?
ValueError: incompatible .mpy fileBertLindeman commentedon Apr 13, 2021
Well . . . If I do no funny things.
Example: stopped a program and then press UP or DOWN button, shows:
No idea why I would want to press UP or DOWN though 😃
And do not know what the cursor keys are supposed to do.
Most browsing keys act the same.
laurensvalk commentedon Apr 13, 2021
Ah, yes, good one. That reminds me of a separate issue 😄
laurensvalk commentedon Apr 13, 2021
I've split the remaining open problems in this thread into separate issues. Thanks for reporting!
dlech commentedon Apr 13, 2021
Yes thanks. Just wanted to verify that even if the hub has problems that Pybricks Code can recover without having to be restarted.