-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
[Bug] await wait(0) does not yield (enough) #1429
Comments
We can simplify this and rule out the from pybricks.tools import run_task, wait
async def main1():
while True:
await wait(0) # second taks only proceeds with nonzero delay
async def main2():
while True:
await wait(0)
print('Hello!')
await wait(500)
async def main():
first = main1()
second = main2()
while True:
print("first")
next(first)
print("second") # never gets here, so main1 is blocking
next(second)
run_task(main()) |
So So we could either
I kind of want to avoid But when looking at this, the loop time doesn't seem to work as intended which is a separate issue. EDIT: Assuming this issue is fixed, it's going to be a 10ms roundtrip around the loop anyway, so maybe we should just use the 1 ms here. |
My gut reaction here is to make |
Fixes suggested in pybricks/pybricks-micropython#262, pybricks/pybricks-micropython#263. While I was thinking about this, it occurred to me we could extend this by making all awaitables yield at least once. For example |
Describe the bug
The following program does not run the second stack of program, i.e. the buttons won't operate the gripper.
To reproduce
Expected behavior
Bad loops are caught by the block language to automatically yield. This is working, but apparently
await wait(0)
does not currently appear to yield at least once when it should.The workaround would be to insert
wait(1)
but it would be better to fix it in the firmware.The text was updated successfully, but these errors were encountered: