You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to do some async initialization for my fastapi server using the FastAPI lifespan parameter: https://fastapi.tiangolo.com/advanced/events/. However, when mounting my FastAPI app to my bento service, the lifespan coroutine is not executed.
Furthermore, bento does not seem to support async initialization in general. The on_deployment decorator does not support an async function and doesn't intake an instantiation of the class.
I expect for the lifespan coroutine to execute. This would mean that I'd see the print statements from the lifespan and test_async_func and that the health endpoint would be exposed from my bento service.
Environment
python: 3.10.15 bentoml: 1.3.19
The text was updated successfully, but these errors were encountered:
The FastAPI app is mounted as a subroute, so the app-level lifespan setting is not being executed.
Now the official way to run service level startup hook is inside __init__ method, which doesn't support async for now.
In fact, how to expose a user-friendly lifespan interface is still a topic worth discussing, and bentoml will also discuss a better API to allow users to customize the behavior of lifespan.
The FastAPI app is mounted as a subroute, so the app-level lifespan setting is not being executed.
Now the official way to run service level startup hook is inside __init__ method, which doesn't support async for now.
In fact, how to expose a user-friendly lifespan interface is still a topic worth discussing, and bentoml will also discuss a better API to allow users to customize the behavior of lifespan.
It should be simple to add another decorator such as @on_startup similar to @on_deployment that wraps a coroutine. Then on ServiceAppFactory.create_instance which is an async func, you can grab all of the coroutines on the inner class with the attr and run an asyncio.gather on them.
Describe the bug
I am attempting to do some async initialization for my fastapi server using the FastAPI lifespan parameter: https://fastapi.tiangolo.com/advanced/events/. However, when mounting my FastAPI app to my bento service, the lifespan coroutine is not executed.
Furthermore, bento does not seem to support async initialization in general. The
on_deployment
decorator does not support an async function and doesn't intake an instantiation of the class.To reproduce
Run the server:
BENTOML_DEBUG=TRUE bentoml serve --working-dir ./src test-lifespan:Service --verbose
My Output
Expected behavior
I expect for the lifespan coroutine to execute. This would mean that I'd see the print statements from the
lifespan
andtest_async_func
and that thehealth
endpoint would be exposed from my bento service.Environment
python
: 3.10.15bentoml
: 1.3.19The text was updated successfully, but these errors were encountered: