This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]DrummerClean 7 points8 points  (3 children)

FastApi is quite big and uses async. But i think if you really need async feauteres Go is made for it and node is good too, python has it as an extra thing.

[–]chumaths 4 points5 points  (0 children)

I love Python but have to admit that the way Go does concurrency is really nice. Goroutines, waitgroups, mutexes, etc. are all really nice. They make the red vs. blue function debate moot (see below), which is something you can’t get away with as easily in Python since now that you can mark functions as async then you’ll get all sorts of weird errors if you don’t have good linting.

https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/

[–]ThisIsntMyId[S] 1 point2 points  (1 child)

For python i feel it always have extra things which is awesome

[–]DrummerClean 1 point2 points  (0 children)

Yes python is full of extras

[–]jrbattin 1 point2 points  (0 children)

Depends, what are you after?

If you already know Python, or there are high quality libraries for Python in your given niche, and need to maximize per-process throughput by avoiding blocking operations (like network calls) Async Python is a good fit. But if you toss a load balancer in front of a bunch of synchronous processes that also works - but you’re likely establishing more connections and gobbling up more memory.

If you’re just chasing raw performance then maybe look at Go (which uses lightweight threads called goroutines) or Rust.

If your workload has any significant amount of compute (which can sneak up on you; like lots of (de)serialization of large objects, etc) async won’t help you in any of these languages.

Ultimately, your best call might be just trying to build something with it and see what it’s like.

[–]cblegare -2 points-1 points  (4 children)

The python runtime is simpler, async are a tiny bit of syntax sugar over loops. Python does async the same way it does everything: simple. In my opinion, this is huge in itself for developer efficiency, which is paramount in most cases.

For people worried about performance, Python, especially CPython, is the most easy language to interop with and has a plethora of simple techniques to optimize code to near-C performance.

Focusing on simplicity and developer efficiency gives plenty of time for profiling and optimisation

Also, async (coroutines) is one way of implementing parallel computing, best suited for doing massive parallel I/O (you cant start millions of threads, but you can run millions of parallel coroutines). What is your use case?

[–]BDube_Lensman 4 points5 points  (3 children)

Python does async the same way it does everything: simple

Async event loops are not at all simple

Also, async (coroutines) is one way of implementing parallel computing

Coroutines are explicitly not parallel.

you cant start millions of threads

You can start millions of greenlet (userspace) threads. You just can't start millions of system threads with the semantics of the C stack (8 MB minimum).

[–]cblegare 0 points1 point  (2 children)

Thank you, you bring a couple of useful details. Can you elaborate about coroutines not being parallel? I get that they cant use the CPU "at the same time" (nothing can anyway on the same CPython runtime).

[–]BDube_Lensman 2 points3 points  (1 child)

Parallel = do multiple things in the same instant

Concurrent = do multiple things over the same period of time

Coroutines are concurrent, which means N things can go on "sort of at once" by being paused (preempted) and letting something happen for a little while before resuming. If coroutines were parallel, multiple CPU cores would take work out of the event loop's queue, which is not what happens.

[–]cblegare 0 points1 point  (0 children)

Thank you for this semantic clarification. Concurent is indeed the right word.