Skip to content

Commit 9cf780d

Browse files
authored
fix: turn off build log stream in jupyter notebook (#5165)
1 parent 023c746 commit 9cf780d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/bentoml/_internal/cloud/deployment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from ..tag import Tag
4141
from ..utils import bentoml_cattr
4242
from ..utils import filter_control_codes
43+
from ..utils import is_jupyter
4344
from ..utils import resolve_user_filepath
4445
from .base import Spinner
4546
from .schemas.modelschemas import BentoManifestSchema
@@ -625,7 +626,7 @@ def tail_image_builder_logs() -> None:
625626
f':hourglass: Waiting for deployment "{self.name}" to be ready. Current status: "{status.status}"'
626627
)
627628
if status.status == DeploymentStatus.ImageBuilding.value:
628-
if tail_thread is None:
629+
if tail_thread is None and not is_jupyter():
629630
tail_thread = Thread(
630631
target=tail_image_builder_logs, daemon=True
631632
)

src/bentoml/_internal/log.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ def filter(self, record: LogRecord) -> bool | LogRecord:
106106
"handlers": ["tracehandler"],
107107
"propagate": False,
108108
},
109+
"uvicorn.error": {
110+
"level": logging.WARNING,
111+
"handlers": ["tracehandler"],
112+
"propagate": True,
113+
},
109114
},
110115
"root": {
111116
"handlers": ["tracehandler"],

src/bentoml/_internal/utils/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,23 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
580580
return wrapper
581581

582582
return decorator
583+
584+
585+
def is_jupyter() -> bool: # pragma: no cover
586+
"""Check if we're running in a Jupyter notebook."""
587+
try:
588+
get_ipython # type: ignore[name-defined]
589+
except NameError:
590+
return False
591+
ipython = get_ipython() # noqa: F821 # type: ignore[name-defined]
592+
shell = ipython.__class__.__name__
593+
if (
594+
"google.colab" in str(ipython.__class__)
595+
or os.getenv("DATABRICKS_RUNTIME_VERSION")
596+
or shell == "ZMQInteractiveShell"
597+
):
598+
return True # Jupyter notebook or qtconsole
599+
elif shell == "TerminalInteractiveShell":
600+
return False # Terminal running IPython
601+
else:
602+
return False # Other type (?)

0 commit comments

Comments
 (0)