-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calls which wait
block all other events
#27
Comments
First noted in #25 |
Without significant refactoring and the introduction of lower level control (maybe even PIO) I am not sure there is anything can be be done to avoid this. While micropython is waiting for a You cant block and wait for the completion of a Timer because for the same reason - no other processing can take place while its waiting.
The use of micropython I think the choices are:
|
@tracygardner I would appreciate your thoughts on this. |
@martinohanlon I think live with it and document it as current behaviour. There are workarounds when you do want the behaviour that you expected. For that situation we would use wait=False and for more complex ones you'd use polling. The convenience of having this as an option seems to outweigh this issue. We can provide plenty of best practice recipes so that beginners go down paths that work well. |
Just adding in this example to separate the issue from wait=True from picozero import LED, Button, pico_led
from time import sleep
led = LED(13)
led.off()
button = Button(18)
pico_led.off()
def change_colour():
led.on()
sleep(5)
led.brightness = 0.25
def stopped():
pico_led.on()
led.off()
button.when_pressed = change_colour
button.when_released = stopped A callback will run to completion, we said this was a limitation at the beginning. Your example just seems to be an instance of this behaviour. At the moment we provide wait=False options for the times when you want to be able to cancel a running blink/pulse/cycle/play. In future it would be nice to be able to 'cancel' user-defined callbacks but I see that as a new feature. |
Consider the following program:
The expected behaivour would be for the LED to blink twice, but as soon as button is released the LED should turn off.
In practice the LED will continue to blink until it has finished.
This issue affects all calls which use
wait
. It becomes more apparent functions likePWMBuzzer.play
which wait by default and it isnt an explicit action by the user to setwait
to True.The text was updated successfully, but these errors were encountered: