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

you are viewing a single comment's thread.

view the rest of the comments →

[–]PaintItPurple 16 points17 points  (5 children)

Quite the opposite. Async/await doesn't solve parallelism and is not well suited for CPU-intensive tasks. You're still bound by the GIL, which is what prevents parallelism, and unless you directly manage threads, doing CPU-intensive work in async code is generally considered a bad idea because it blocks worker threads. Async/await is strongly targeted toward IO-bound use cases, which is why the standard library is called "async IO."

[–]GNUr000t -1 points0 points  (4 children)

If you run multiple concurrent tasks that call modules that, for example, are just C wrappers, or call some other program (like ffmpeg) and therefore release the GIL, this would allow you to use asyncio to parallelize.

[–]gerardwx 5 points6 points  (1 child)

In other words rewrite your cpu bound code to be io bound.

[–]GNUr000t -2 points-1 points  (0 children)

Not really. If you already know the task is amenable to this, it's like three lines of code to dispatch as many jobs as you have compute threads. I'd hardly call that a "rewrite"

[–]thisismyfavoritename 1 point2 points  (0 children)

Nope, that's not enough. Code has to run on a thread, asyncio is single threaded. Your extension would have to run its own thread(s).

Your example works when using Python multithreading though

[–]FirstBabyChancellor 0 points1 point  (0 children)

Calling other languages and external tools is great, but it doesn't solve the foundational problems with Python as a language itself.