News for hackers. Stuff that matters.
Re:Python Asyncio: The Complete Guide by matsemann on Thursday November 10, 2022 @01:23PM (#33550851)
In other languages the async paradigm work for multiple kind of workflows, not just heavily IO bound ones.
Re:Python Asyncio: The Complete Guide by number6 on Thursday November 10, 2022 @01:32PM (#33550986)
Can you give me an example which languages do this?
Re:Python Asyncio: The Complete Guide by matsemann on Thursday November 10, 2022 @01:40PM (#33551117)
In Kotlin for instance you can run your coroutines with different "dispatchers", which have different behaviors. You can for instance use a dispatcher with multiple threads in a threadpool, run it in the main thread, a specific thread, in threads with low/high priority etc. Basically allowing you to write code using the async/coroutine paradigm, but then control its execution from the outside.
Re:Python Asyncio: The Complete Guide by tmh88j on Thursday November 10, 2022 @02:30PM (#33551788)
> In Kotlin for instance you can execute your coroutines with different "dispatchers", which have different behaviors. You can for instance use a dispatcher with multiple threads in a threadpool, run it in the main thread, a specific thread, in threads with low/high priority etc. Basically allowing you to write code using the async/coroutine paradigm, but then control its execution from the outside.

I'm not very experienced with Kotlin, but that sounds similar to python's run_in_executor [1]

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

Re:Python Asyncio: The Complete Guide by throwaway81523 on Monday November 14, 2022 @07:27PM (#33603507)
Look at seastar.io which is an async concurrency library for C++. It is painful in that it resembles node.js but it is very performant. I'd be interested in seeing a version adapted to use C++20 coroutines.
Re:Python Asyncio: The Complete Guide by qwertox on Thursday November 10, 2022 @04:39PM (#33553787)
But it only does so because you can move out that extra work from the async thread into a thread pool.

In Python there's no benefit in doing this due to the GIL, unless you're using a module which implements its own multithreading (for example in C). Python is not alone with this issue.

In other languages you're basically stepping out of the async paradigm in order to use threading in parallel. You can wait for result of the thread in the async loop without blocking.

I really enjoy using asyncio in Python for things where I have to do a lot of stuff in parallel, like executing remote scripts in a dozen of servers in parallel via AsyncSSH or for low workload servers which query databases.

In any case, what keeps me hooked on Python like a junkie is the `reload(module)` which I invoke via an inotify hook every time a file/module changes:

server.py

server_handler.py

reloader.py

server.py loads reloader.py (which sets up inotify) and that one takes care of reloading server_handler.py whenever it changes. server.py defers all the request/response handling to server_handler.py which can be edited on the fly so that the next request executes the new code. Instant hot reloading.

This also works very nice with asyncio (like aiohttp) and one ends up with very readable code.

If you need performance, then use Java, Rust, Go or C/C++, but for prototyping and tooling I absolutely love this approach with Python.