Mariano Semelman
05/14/2024, 9:25 AMSean
05/14/2024, 9:46 AMMariano Semelman
05/14/2024, 9:46 AMMariano Semelman
05/14/2024, 9:49 AMMariano Semelman
05/14/2024, 9:58 AMclass BackgroundJSON(io_descriptors.JSON):
....
async def to_http_response(..., ctx):
response = super().to_http_response()
... # check ctx is present
response.background = ctx.background
return response
Sadly, I would need to change ServiceContext as wellMariano Semelman
05/14/2024, 9:59 AMSean
05/14/2024, 10:01 AMI wish there was a way to access to Starlette Response object more easilyThanks for the feedback. We are evaluating designs on exposing the Starlette response.
Sean
05/14/2024, 10:02 AMMariano Semelman
05/14/2024, 10:03 AMMariano Semelman
05/14/2024, 10:03 AMMariano Semelman
05/14/2024, 10:04 AMSean
05/14/2024, 10:07 AM@bentoml.api
def predict(self, arg):
# model inference
result = self.model.predict(arg)
def send_kafka_event():
...
# Start a new thread for the task
thread = threading.Thread(target=send_kafka_event)
thread.start()
return resultMariano Semelman
05/14/2024, 10:08 AMSean
05/14/2024, 10:08 AMasyncio has some more elegant functions.Mariano Semelman
05/14/2024, 10:09 AManyio as wellMariano Semelman
05/14/2024, 10:09 AMSean
05/14/2024, 10:09 AMcreate_task is what you are looking for if using asyncio.Vasileios Zografos
05/14/2024, 10:09 AMVasileios Zografos
05/14/2024, 10:11 AM<http://anyio.to|anyio.to>_threadSean
05/14/2024, 10:21 AMSohail Khan
05/15/2024, 4:05 AM