4 ms·
>They will not make two calculations at the same time (can't use several CPU cores like with multiprocessing) Not true. Future executors can run in processors
by Uptrenda 3y ago
>They will not make two calculations at the same time (can't use several CPU cores like with multiprocessing)
Not true. Future executors can run in processors pool (with different cores) or using threads (same core, different event loops.)
>You have to understand that async programming is hard, and no matter how good the tooling is, it's going to make your code more difficult to manage. It has a high price.
Dude starts out with an article that lists the entire kitchen sink for concurrency; Neglecting to mention that literally none of these libraries are even considered by Python devs. Then concludes that writing async code is too hard (writing 'await' before a call is too hard.)
To me this entire article reads like someone's attempt to over-complicate things by trying to overwhelm you with information to seem impressive even though 99% of it is irrelevant to the discussion. Then makes a non-sequitur conclusion to make it seem like only 'experts' ought to touch any of this because [for you] (le simple-minded pleb) you will inevitably break everything. Lmao, fuck that, that's condescending as hell. Literally just using async def for functions that do IO and write await. There's a few things to learn but any dev is capable of doing it.
>I’ll add you probably should not go with asyncio manually. Use a higher level asyncio based lib, or better, framework. Async is hard enough as it is.
Horrible advice. Asyncio is high level already and comes standard in Python 3.6 >=. You will get far more trouble using third-party concurrency libraries than trying to use the Python library which is actually very elegant and well-supported. Twisted sucks, by the way.
- pphysch 3y ago> Literally just using async def for functions that do IO and write await. If only it were that simple. > You will get far more trouble using third-party concurrency libraries than trying to use the Python library which is actually very elegant Again, you overlook the fact that asyncio requires you to explicitly launch a concurrent context. Asyncio is fine, but it is not "elegant" because of this.
- evil-olive 3y ago> asyncio requires you to explicitly launch a concurrent context `asyncio.run()` [0] was added in 3.7, and as far as I know is the current recommended way to do this. as shown in the asyncio "hello world" example [1], you can write your main() function to be async, and then the entire process runs asynchronously from the beginning. and as shown on that page, you can also use `python -m asyncio` to get a REPL with a running event loop where using `await` will work as you'd expect it to. one of my biggest quibbles with a lot of asyncio demo code snippets is the use of `loop.run_until_complete()` [2] and similar lower-level primitives. in most asyncio applications you simply want to start the loop as early as possible with `asyncio.run(main())`, let it run for the duration, and have the entire process exist in async-land. 0: https://docs.python.org/3/library/asyncio-runner.html#asyncio.run https://docs.python.org/3/library/asyncio-runner.html#asynci... 1: https://docs.python.org/3/library/asyncio.html https://docs.python.org/3/library/asyncio.html 2: https://stackoverflow.com/questions/40143289/why-do-most-asyncio-examples-use-loop-run-until-complete https://stackoverflow.com/questions/40143289/why-do-most-asy...
- pphysch 3y agoYes, these are some ways to get that context. But it can be difficult to do correctly for brownfield projects or libraries, especially if you need to support both sync and async. Not elegant!
- evil-olive 3y ago> especially if you need to support both sync and async I don't think there's any possible way to do that elegantly. maybe gevent-style monkeypatching makes it look elegant, but there's a whole pile of inelegant stuff happening under the covers to present that illusion. and I would say that almost by definition, if you're monkeypatching the stdlib, you are banished from the realm of elegance.