This repository has been archived by the owner. It is now read-only.
For fun and API calls
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Very simple async http requests


Learning Node, the one thing that's interesting is the ability to make lots of requests asynchronously. This would be useful if:

  1. You depending on many microservices or API's
  2. You want to download all the files in a blogpost, like Django Draftin does.

Can Python do this?

It does have new async features. Some inspiration and sample code:


What works well

Making very small async tasks and pulling them into a synchronous function. Kept simple, this could give us 95% of the benefits of async with the minimum confusion.

What barely works

Asyncio's docs are overwhelming. The fact that this also confuses Armin Ronacher suggests its not just my tiny imposter brain that finds it unapproachable.

aiohttp helps, but seems to leave out the simplest use case: the equivelant of:

    resp = request.get("")
except Exception:
    msg = "Help! Something went horribly wrong!"

I hacked around it. It's not great.

What doesn't work at all

If you're running Flask in debug mode, as one does, you get a mysterious error:

RuntimeError: There is no current event loop in thread 'Thread-1'.

I can't find any useful insight into this.

Other Approaches

There's an asyncio-based microframework called Quart that follows the Flask API. Example branch courtesy of @pgjones