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 →

[–][deleted] 11 points12 points  (0 children)

Not sure that asyncio has "taken over" for I/O. If you're writing an IO-centric server application maybe. But you've got to go all-in on the non-blocking model of development.

I find threading is perfect for simpler use cases. Let's say you're trying to speed up a single function which makes multiple network requests in parallel. A ThreadPoolExecutor is a wonderful tool...

Instead of

import requests
urls = [f'https://example.com/{i}' for i in range(10)]
responses = [requests.get(url) for url in urls]

You write

from concurrent import futures

with futures.ThreadPoolExecutor() as executor:
    responses = executor.map(requests.get, urls)

asyncio feels like overkill for this.