Skip to content

Commit 015551c

Browse files
committed
Make colab_run a no-op when not running in colab env
1 parent f297409 commit 015551c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

mesop/server/colab_run.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
from mesop.server.logging import log_startup
77
from mesop.server.server import configure_flask_app
88
from mesop.server.static_file_serving import configure_static_file_serving
9+
from mesop.utils.colab_utils import is_running_in_colab
910

1011

1112
def colab_run():
1213
"""
13-
Typically only used for Colab/Jupyter notebooks, otherwise you'll use the CLI
14-
to execute a Mesop application.
14+
When running in Colab environment, this will launch the web server.
15+
16+
Otherwise, this is a no-op.
1517
"""
18+
if not is_running_in_colab():
19+
print("Not running Colab: `colab_run` is a no-op")
20+
return
1621
flask_app = configure_flask_app()
1722
enable_debug_mode()
1823
configure_static_file_serving(

mesop/utils/colab_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import builtins
2+
import sys
3+
4+
5+
def is_running_in_colab() -> bool:
6+
return "google.colab" in sys.modules and hasattr(builtins, "get_ipython")

0 commit comments

Comments
 (0)