State passed into startup and shutdown handlers #1856
-
I have a number of applications that have particular "state" needed in the startup handlers. It would be great to get the state passed in. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
isn't that what you're lookig for @eprparadocs : https://www.starlette.io/applications/#storing-state-on-the-app-instance |
Beta Was this translation helpful? Give feedback.
-
I tried that but something between the creation of the FASTapi() app
variable, and the invocation of the startup caused the state to vanish. In
fact what happens is that after the innovation of the on_start the state
got wiped out,
I traced it down to a rather interesting problem. When my code starts up it
is running in PID x. and after the server.server() is executed the pid is
different, and the 'app' is reinitialized (because the module has been
reloaded). So the state is completely gone.
I'm not exactly who's fault this is starlette or FASTapi. But it is
absolutely repeatable and why I wrote the original entry.
Chance
…On Mon, Sep 12, 2022 at 4:30 AM euri10 ***@***.***> wrote:
isn't that what you're lookig for @eprparadocs
<https://github.com/eprparadocs> :
https://www.starlette.io/applications/#storing-state-on-the-app-instance
—
Reply to this email directly, view it on GitHub
<#1856 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAATQTPUN6YDVW5XOG7YHNTV53SYVANCNFSM6AAAAAAQJJZCKQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Found it! Turns out to be an issue in uvicorn! For some reason - haven't
gotten there yet - app variable is re-initialized using the state. So
either I have it wrong in my code (though it comes from a sample someone
wrote for the documentation) or there is something else going on.
On Mon, Sep 12, 2022 at 10:43 AM Charles Wegrzyn ***@***.***>
wrote:
… I tried that but something between the creation of the FASTapi() app
variable, and the invocation of the startup caused the state to vanish. In
fact what happens is that after the innovation of the on_start the state
got wiped out,
I traced it down to a rather interesting problem. When my code starts up
it is running in PID x. and after the server.server() is executed the pid
is different, and the 'app' is reinitialized (because the module has been
reloaded). So the state is completely gone.
I'm not exactly who's fault this is starlette or FASTapi. But it is
absolutely repeatable and why I wrote the original entry.
Chance
On Mon, Sep 12, 2022 at 4:30 AM euri10 ***@***.***> wrote:
> isn't that what you're lookig for @eprparadocs
> <https://github.com/eprparadocs> :
> https://www.starlette.io/applications/#storing-state-on-the-app-instance
>
> —
> Reply to this email directly, view it on GitHub
> <#1856 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAATQTPUN6YDVW5XOG7YHNTV53SYVANCNFSM6AAAAAAQJJZCKQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
-
Now, it's possible with Lifespan State. |
Beta Was this translation helpful? Give feedback.
Now, it's possible with Lifespan State.