question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make ASGI dispatcher asyncio-agnostic

See original GitHub issue

Note: this issue breaks apart steps originally taken in #217.

The ASGI dispatcher currently relies on asyncio-specific APIs to perform various operations, which is a blocker towards supporting alternative concurrency backends.

We want to make sure all of the I/O inside ASGIDispatch goes through the backend instead.

This will need the following, most of which can be tackled in independant PRs:

  • #257 Hard-code self.backend = AsyncioBackend() on ASGIDispatch to be able to iteratively defer asyncio-specific APIs to the backend.

  • #257 Introduce a queue-like interface:

class BaseQueue:
    async def get(self): ...
    async def put(self, value: typing.Any): ...

along with a .create_queue() method on ConcurrencyBackend, to be used instead of/within the BodyIterator.

(For trio we’ll probably need to add a .close() method as well, but that can be confirmed and tackled in due time.)

  • #260 Introduce a BaseEvent interface:
class BaseEvent:
    def set(self): ...
    def is_set(self): ...
    async def wait(self): ...

along with a .create_event() method on ConcurrencyBackend to abstract asyncio.Event().

  • #261 Remove usage of loop.create_task() via the background manager interface.

  • Lastly, turn the hard-coded backend into a parameter. Make sure it is optional and we use AsyncioBackend as a default.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tomchristiecommented, Aug 20, 2019

Yeah it’ll tie in. We’ll want to get this side of things all nice and clean and sorted first, then we’ll be able to take a proper look at #52 again.

1reaction
tomchristiecommented, Aug 20, 2019

Going to see if I can take a crack at dropping the asyncio.FIRST_COMPLETED bit of implementation, since that’d make this issue somewhat narrower in scope.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Framework-agnostic Library for Testing ASGI Web ... - Morioh
Async ASGI TestClient is a library for testing web applications that implements ASGI specification (version 2 and 3). The motivation behind this project...
Read more >
An Asyncio socket tutorial - Medium
An Asyncio socket tutorial. How to build an ASGI web server, like Hypercorn. There are many asyncio tutorials and articles that focus on ......
Read more >
anyio — Reverse Dependencies - Wheelodex
aiometer — A Python concurrency scheduling library, compatible with asyncio and trio; aiopath — Async pathlib for Python; aioprometheus-api-client — An async ...
Read more >
Async IO in Python: A Complete Walkthrough
Here's what you'll cover: Asynchronous IO (async IO): a language-agnostic paradigm (model) that has implementations across a host of programming languages.
Read more >
asyncore — Asynchronous socket handler — Python 3.11.1 ...
The basic idea behind both modules is to create one or more network channels, instances of class asyncore.dispatcher and asynchat.async_chat .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found