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
Running a while True loop without anything in the loop to make the thread sleep will cause Python to use 100% CPU.
Since ev3dev-stretch R3, this is especially noticeable since the user program is run with higher priority (nice -10) and it will starve the rest of the operating system that is running at a lower priority. This has side-effects like making the stop button in the ev3dev VS Code extension slow to respond.
The added sleep can be time.sleep() or anything that does a blocking wait for at least a millisecond or two (poll() with timeout, waiting for a sound to finish playing, etc.).
Example programs, such as this one from the README should be modified similar to this:
ts=TouchSensor()
leds=Leds()
print("Press the touch sensor to change the LED color!")
whileTrue:
ifts.is_pressed:
leds.set_color("LEFT", "GREEN")
leds.set_color("RIGHT", "GREEN")
else:
leds.set_color("LEFT", "RED")
leds.set_color("RIGHT", "RED")
# don't use 100% CPUtime.sleep(0.01)
The text was updated successfully, but these errors were encountered:
Running a
while True
loop without anything in the loop to make the thread sleep will cause Python to use 100% CPU.Since ev3dev-stretch R3, this is especially noticeable since the user program is run with higher priority (nice -10) and it will starve the rest of the operating system that is running at a lower priority. This has side-effects like making the stop button in the ev3dev VS Code extension slow to respond.
The added sleep can be
time.sleep()
or anything that does a blocking wait for at least a millisecond or two (poll()
with timeout, waiting for a sound to finish playing, etc.).Example programs, such as this one from the README should be modified similar to this:
The text was updated successfully, but these errors were encountered: