4 ms·
asyncio is really not all about I/O though, despite the name. You can just as easily use it for concurrency by interleaving tasks with each other. You can imagi
by vore 4y ago
asyncio is really not all about I/O though, despite the name. You can just as easily use it for concurrency by interleaving tasks with each other. You can imagine multiple UI elements that all need to make progress, and using coroutines to have them cooperatively yield to each other and not just have one element block progress everywhere else.
It's just using asyncio as a task scheduler, nothing more, nothing less. Maybe when you visit Pythonland you might instead be shocked in a more positive way :-)
- crabbone 4y ago[flagged]
- vore 4y agoI can't help but feel this is a low-effort troll, but I'll bite anyway. > Where does this nonsense come from? Seriously? Who told you that? Where is the I/O in this? async def task1(): while True: print("a") await asyncio.sleep(0) async def task2(): while True: print("b") await asyncio.sleep(0) async def main(): t1 = asyncio.create_task(task1()) t2 = asyncio.create_task(task2()) await asyncio.gather(t1, t2) asyncio.run(main()) Fundamentally it's an event loop that allows you to register interest in I/O events. You can, of course, also just register no interest in any I/O events, where you still get scheduler features like timers and cooperative scheduling. > This is wishful thinking. No. It doesn't work. Will not work, unless Python is purged of like 99% of it's current stuff and replaced with something else entirely. It's ridiculous to even consider this possibility applied to the concrete runtime you'd have to work with. Where is the wishful thinking in the same code example I posted? You are free to control cooperation between your tasks as required. > Come on man... you just put "cooperatively" and "will not block" in the same sentence. Of course it doesn't work like that. Will not work, especially in Python where you have to yield control explicitly. It's all toys. None of it works. So? Just yield control explicitly? Just because the multitasking isn't preemptive doesn't mean you can't cooperatively make progress on multiple tasks. > Well, that's stupid. Why would anyone want to do that? It simply won't work. It works fine? The post is literally talking about how it works? Maybe you don't like the ergonomics but that's not a reason to be so dismissive of it. In any case, just because you don't like it doesn't mean there is zero value in this, or that you can be such a massive piece of shit and respond like this.