Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> There is no reason a scheduler could not be totally lazy and only execute the coroutine once awaited.

Isn't the point of create_task (which is what the article is about) to launch concurrent tasks without immediately awaiting them? The example in the docs [1] wouldn't work (in the stated manner) if the task didn't start until it was awaited.

> At least he bothered to make note of TaskGroups [...] Yep, that's all there was to it.

That only works on Python 3.11, which was released just a few months ago. Debian still uses 3.9, for example, so the TaskGroups solution can't be used everywhere yet.

[1] https://docs.python.org/3/library/asyncio-task.html#coroutin...



The reason I said "on a more fundamental level" is that I'm not talking specifically about Python and asyncio, but coroutines in general. Even for Python, there are multiple event loop libraries available, they do not all work identically, which is why multiple ones exist. Someone here mentioned Temporal Python which works differently from asyncio, and would have avoided the author's problem. If you don't know how the scheduler works, you can't assume that a coroutine is guaranteed to complete just because you yoloed it into the scheduler, no matter how convenient that might be for you.

Yes, TaskGroups are a recent addition. If you can't use Python 3.11 for whatever reason, there is also the clearly written code sample at the bottom of the create_task documentation, which the author did not bother to mention. Probably didn't make it that far.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: