-
-
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] Improve async loop time #1460
[Bug] Improve async loop time #1460
Comments
The following works as "intended", but this is somewhat questionable. The async loop time is set to from pybricks.tools import run_task, wait, StopWatch
watch = StopWatch()
async def main1():
while True:
await wait(1)
print(watch.time())
run_task(main1())
|
On second thought, the issue I thought I was originally seeing wasn't due to async, so this is not as critical as I thought. It's probably still worth considering the |
Another possibility is to leave it at 10 ms, and provide an option to avoid auto-inserting loop trap yields for more advanced users. |
Also, it would be nice to avoid inserting it if there is already a known, nonzero constant wait in the loop at the same nesting level. We should be able to detect this quite easily since we know the inner stack of block when we generate the code for the loop. EDIT: We might only be able to do this if that wait is guaranteed to run (e.g. sits at the top). Right now, if you have a 1 ms loop and you then switch to multitask (which adds another 1ms wait), the loop actually takes 20 ms, since the async loop time is 10ms right now. |
Could we expose the loop time in the "set up" hat block? I.e. If there is only one "program" hat block, nothing changes. If there is more than one "program" hat block then "set up" grows an extra parameter for the loop time. This would make it somewhat obvious that there is an implicit loop time shared by all parallel tasks. And that way, people could tweak the default 10ms loop time if needed. |
That's a good idea. I was thinking about having some kind of extra (and thereby optional) block to configure that sort of thing. Besides the async loop time, we could allow users to configure if (and/or how much) waits are injected in loops and functions. Power users could opt to skip inserting waits. Right now, iterating through a list to do some operation also takes 10ms each iteration for example, which is probably undesired in (finite) data processing cases. |
In #1780 it was suggested to drop the What remains then is to change the block code generator to insert |
This isn't done yet, so re-opening. |
Fixed and released in latest beta. |
The loop time doesn't seem to work as intended which is a separate issue.
Originally posted by @laurensvalk in #1429 (comment)
The text was updated successfully, but these errors were encountered: