Skip to content

Commit

Permalink
fix: turn off build log stream in jupyter notebook (#5165)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored Jan 3, 2025
1 parent 023c746 commit 9cf780d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from ..tag import Tag
from ..utils import bentoml_cattr
from ..utils import filter_control_codes
from ..utils import is_jupyter
from ..utils import resolve_user_filepath
from .base import Spinner
from .schemas.modelschemas import BentoManifestSchema
Expand Down Expand Up @@ -625,7 +626,7 @@ def tail_image_builder_logs() -> None:
f':hourglass: Waiting for deployment "{self.name}" to be ready. Current status: "{status.status}"'
)
if status.status == DeploymentStatus.ImageBuilding.value:
if tail_thread is None:
if tail_thread is None and not is_jupyter():
tail_thread = Thread(
target=tail_image_builder_logs, daemon=True
)
Expand Down
5 changes: 5 additions & 0 deletions src/bentoml/_internal/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def filter(self, record: LogRecord) -> bool | LogRecord:
"handlers": ["tracehandler"],
"propagate": False,
},
"uvicorn.error": {
"level": logging.WARNING,
"handlers": ["tracehandler"],
"propagate": True,
},
},
"root": {
"handlers": ["tracehandler"],
Expand Down
20 changes: 20 additions & 0 deletions src/bentoml/_internal/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,23 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
return wrapper

return decorator


def is_jupyter() -> bool: # pragma: no cover
"""Check if we're running in a Jupyter notebook."""
try:
get_ipython # type: ignore[name-defined]
except NameError:
return False
ipython = get_ipython() # noqa: F821 # type: ignore[name-defined]
shell = ipython.__class__.__name__
if (
"google.colab" in str(ipython.__class__)
or os.getenv("DATABRICKS_RUNTIME_VERSION")
or shell == "ZMQInteractiveShell"
):
return True # Jupyter notebook or qtconsole
elif shell == "TerminalInteractiveShell":
return False # Terminal running IPython
else:
return False # Other type (?)

0 comments on commit 9cf780d

Please sign in to comment.