Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exception): catch exception for users' runners code #4150

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/bentoml/_internal/server/runner_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import pickle
import traceback
import typing as t
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -205,7 +206,11 @@ async def inner():
# This is a workaround to allow infer stream to return a iterable of
# async generator, to align with how non stream inference works
params = paramss[0].map(AutoContainer.from_payload)
ret = runner_method.async_stream(*params.args, **params.kwargs)
try:
ret = runner_method.async_stream(*params.args, **params.kwargs)
except Exception:
traceback.print_exc()
raise
async for data in ret:
payload = AutoContainer.to_payload(data, 0)
yield payload
Expand Down Expand Up @@ -236,9 +241,13 @@ async def infer_batch(
params_list, input_batch_dim
)

batch_ret = await runner_method.async_run(
*batched_params.args, **batched_params.kwargs
)
try:
batch_ret = await runner_method.async_run(
*batched_params.args, **batched_params.kwargs
)
except Exception:
traceback.print_exc()
raise

# multiple output branch
if LazyType["tuple[t.Any, ...]"](tuple).isinstance(batch_ret):
Expand Down Expand Up @@ -268,7 +277,13 @@ async def infer_single(paramss: t.Sequence[Params[t.Any]]):

params = paramss[0].map(AutoContainer.from_payload)

ret = await runner_method.async_run(*params.args, **params.kwargs)
try:
ret = await runner_method.async_run(
*params.args, **params.kwargs
)
except Exception:
traceback.print_exc()
raise

payload = AutoContainer.to_payload(ret, 0)
return (payload,)
Expand Down