Opened 4 months ago

Last modified 4 months ago

#31508 new New feature

ASGI Lifespan Support

Reported by: Braunson Owned by: nobody
Component: HTTP handling Version: 3.0
Severity: Normal Keywords:
Cc: Andrew Godwin, Carlton Gibson Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello, I am deploying my website with Uvicorn and I know I get warnings that ASGI Lifespan is not supported in the Django project.

I was wondering if this was on the roadmap or if I could update the docs in some way? Thanks.

Change History (8)

comment:1 Changed 4 months ago by felixxm

Cc: Andrew Godwin Carlton Gibson added

comment:2 Changed 4 months ago by Carlton Gibson

Component: UncategorizedHTTP handling
Type: UncategorizedNew feature

Hi. I'm inclined to Accept this as a New Feature.

Lifespan is optional (IIUC) but I can imagine folks wanting to use it. (Not sure what for exactly but... :)
I can't immediately see where the right place for the hooks would be. I guess I'd start with an ASGI middleware, at least as PoC.

Accepting provisionally on that basis. Interested to see what Andrew thinks...?

(Seems a bit keen for uvicorn to warn over this, with that whole being optional thing... 🤔 — I guess you could pass --lifespan=off maybe. )

Last edited 4 months ago by Carlton Gibson (previous) (diff)

comment:3 Changed 4 months ago by Carlton Gibson

Triage Stage: UnreviewedAccepted

comment:4 Changed 4 months ago by Adam (Chainz) Johnson

I know they're unpopular, but seems like an opportunity to use signals?

comment:5 Changed 4 months ago by Carlton Gibson

Hmmm. At least until signal dispatch is async, I'm not sure that's an option.

comment:6 Changed 4 months ago by Andrew Godwin

The question I would ask first is "why do we need it?". Django already has somewhat of its own lifespan controls (in app.ready() and similar), so I would want to be sure we are solving a useful problem here rather than just adding it for the sake of completeness.

comment:7 in reply to:  2 Changed 4 months ago by Braunson

Replying to Carlton Gibson:

Hi. I'm inclined to Accept this as a New Feature.

Lifespan is optional (IIUC) but I can imagine folks wanting to use it. (Not sure what for exactly but... :)
I can't immediately see where the right place for the hooks would be. I guess I'd start with an ASGI middleware, at least as PoC.

Accepting provisionally on that basis. Interested to see what Andrew thinks...?

(Seems a bit keen for uvicorn to warn over this, with that whole being optional thing... 🤔 — I guess you could pass --lifespan=off maybe. )

That is true, you can manually disable it in uvicorn. There is use cases for this. One such is Async libraries that only offer asynchronous means of initialization. For instance Elasticsearch's async calls can be initialized with await client.login(...) for example. If you try to use the client without this awaited login it will fail.

So a lifespan feature where you could run some async code for constructing objects would be super useful for me.

comment:8 Changed 4 months ago by Carlton Gibson

Hi Braunson.

Makes sense. Perhaps, for first pass, it would be something we could add as a middleware to Channels? We could take that easily.

I'm planning a new version there in time for Django 3.1, where even if you got a PR together right away, it's unlikely this could land in Django before 3.2 (if at all...)

If such a thing lived in Channels for a while we could see if there was demand for pulling it into Django.

Fancy taking a pop at it? (Happy to advise...)

Last edited 4 months ago by Carlton Gibson (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top