4 ms·
No, asyncio's implementation exists because threading in Python has huge overhead for switching between threads and because threads don't use more than one core
by bmitc 2y ago
No, asyncio's implementation exists because threading in Python has huge overhead for switching between threads and because threads don't use more than one core. So asyncio was introduced as a single threaded solution specifically for only network-based IO.
In any other language, async is implemented on top of the threading model, both because the threading model is more efficient than Python's and because it actually supports multiple cores.
Multiprocessing isn't needed in other languages because, again, their threading models support multiple cores.
So the three, relatively incompatible paradigms of asyncio, threading, and multiprocessing specifically in Python are indeed separate attempts to account for Python's poor design. Other languages do not have this embedded complexity.
- cwalv 2y ago> In any other language, async is implemented on top of the threading model There are a lot of other languages. Javascript for example is a pretty popular language where async on a single threaded event loop has been the model since the beginning. Async is useful even if you don't have an interpreter that introduces contention on a single "global interpreter lock." Just look at all the languages without this constraint that still work to implement async more naturally than just using callbacks. Threads in Python are very useful even without removing the gil (performance critical sections have been written as extension modules for a long time, and often release the gil). > are indeed separate attempts to account for Python's poor design They all have tradeoffs. There are warts, but as designed it fits a particular use case very well. Calling Python's design "poor" is hubris. > So my question is, how does this change affect the decision tree for selecting which paradigm(s) to use? The only effect I can see is that it reduces the chances that you'll reach for multiprocessing, unless you're using it with a process pool spread across multiple machines (so they can't share address space anyway)
- bmitc 2y ago> Calling Python's design "poor" is hubris. Not in the least. Python is a poorly designed language by many accounts. Despite being the most popular language in the world, what language has it significantly influenced? None of note.
- fastasucan 2y agoWho cares about how many other languages a language has influenced? If that was a metric of any consideration we all would write Algol or something. Programming languages are tools, tools to help you perform a task.
- cwalv 2y ago> Python is a poorly designed language by many accounts Hubris isn't rare. > what language has it significantly influenced? I can think of at least 1 language designer[1] who doesn't think it's "poorly designed," based on it's significant impact on what they're currently working on[2] 1. https://en.m.wikipedia.org/wiki/Chris_Lattner https://en.m.wikipedia.org/wiki/Chris_Lattner 2. https://www.modular.com/mojo https://www.modular.com/mojo