-
Notifications
You must be signed in to change notification settings - Fork 0
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
modify parameters passed to asyncio.wait to avoid deprecation warning. #160
Conversation
Are you certain these are synonymous? |
Yes. previously, you had: current: asyncio.Future = asyncio.sleep(self.sleep_time(when)) which is not a future (as the typing suggests) but a coroutine as per the docs. This change makes it a task, which is an object that runs a coroutine. Basically it adds a layer of wrapping around a coroutine, to comply with python 3.11 standards. So before, we were setting up a coroutine and then awaiting it. Now, we are setting up a task and awaiting it, at which point we await the coroutine. They are functionally exactly the same. |
I'm not entirely sure on this but I think they're not the same in general but in this case it doesn't make any difference. |
Is there any advantage to leaving the type annotation there now that it is correct? |
is a task a future? Technically we've made some tasks so why not have asyncio.Task typing for both this line and the one below it instead? Leaving them out, mypy seems to understand what types they are also - I'm assuming pyright would be the same. |
Yeah, they're really quite different, |
It's a good point. I think the docs aren't very clear about this behaviour: ' Wrap the coro coroutine into a Task and schedule its execution ' is what you get when looking at asyncio.Task(). 'schedule its execution' doesn't sound eager to me. could we use asyncio.gather instead? That seems to just take awaitables. |
Currently I see two solutions to this:
new = asyncio.create_task(self.new_wakeup.wait())
which, _ = await asyncio.wait(
[asyncio.create_task(asyncio.sleep(self.sleep_time(when))), new], return_when=asyncio.tasks.FIRST_COMPLETED
) Thoughts? Or am i missing potential solutions to this/ are the solutions above not ideal? |
This won't work as we need to check the task handle returned is the task which returns on an interrupt: if new in which:
return The correct solution is exactly what you have in the PR 🤣 we're all just bikeshedding |
yeah, i guess gather also wouldn't work because I don't see a way to just return when one awaitable completes... What do you think of the 2nd solution? Surely this minimises how eager 'create_task' is for the sleep? |
I'm not quite willing to jump into the bytecode, but I expect it's functionally equivalent to: new = asyncio.create_task(self.new_wakeup.wait())
current = asyncio.create_task(asyncio.sleep(self.sleep_time(when)))
which, _ = await asyncio.wait(
[current, new], return_when=asyncio.tasks.FIRST_COMPLETED
) I wouldn't want to sacrifice readability for a few microseconds in this case, also, I'm not sure if late or early is more correct anyway |
Codecov Report
@@ Coverage Diff @@
## master #160 +/- ##
=======================================
Coverage 94.69% 94.69%
=======================================
Files 44 44
Lines 1264 1264
=======================================
Hits 1197 1197
Misses 67 67
|
Remove asyncio.wait deprecation warning by only passing tasks to it.
In the master scheduler _do_task method, a coroutine is passed to asyncio.wait. This is deprecated behaviour. I noticed this while working on #153: