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

allow --global-session for marimo run #2489

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions marimo/_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def edit(
base_url=base_url,
allow_origins=allow_origins,
redirect_console_to_browser=True,
global_session=True,
)


Expand Down Expand Up @@ -550,6 +551,17 @@ def new(
type=bool,
help="Redirect console logs to the browser console.",
)
@click.option(
"--global-session",
is_flag=True,
default=False,
show_default=True,
type=bool,
help="""
Run a single session and reconnect when the connection is lost,
similar to edit mode
""",
)
@click.option(
"--sandbox",
is_flag=True,
Expand All @@ -575,6 +587,7 @@ def run(
base_url: str,
allow_origins: tuple[str, ...],
redirect_console_to_browser: bool,
global_session: bool,
sandbox: bool,
name: str,
args: tuple[str, ...],
Expand Down Expand Up @@ -612,6 +625,7 @@ def run(
cli_args=parse_args(args),
auth_token=_resolve_token(token, token_password),
redirect_console_to_browser=redirect_console_to_browser,
global_session=global_session,
)


Expand Down
9 changes: 6 additions & 3 deletions marimo/_server/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ def __init__(
cli_args: SerializedCLIArgs,
auth_token: Optional[AuthToken],
redirect_console_to_browser: bool = False,
global_session: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can rename to global_session_in_run_mode or something similar. it is verbose, but this could be confused that edit mode also as global session configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah certainly, any name that makes sense is good for me :)

) -> None:
self.file_router = file_router
self.mode = mode
Expand All @@ -674,6 +675,7 @@ def __init__(
self.user_config_manager = user_config_manager
self.cli_args = cli_args
self.redirect_console_to_browser = redirect_console_to_browser
self.global_session = global_session

# Auth token and Skew-protection token
if auth_token is not None:
Expand Down Expand Up @@ -772,9 +774,10 @@ def maybe_resume_session(
If it is resumable, return the session and update the session id.
"""

# If in run mode, only resume the session if it is orphaned and has
# the same session id, otherwise we want to create a new session
if self.mode == SessionMode.RUN:
# If we dont have a global session, only resume the session if it
# is orphaned and has the same session id,
# otherwise we want to create a new session
if not self.global_session:
maybe_session = self.get_session(new_session_id)
if (
maybe_session
Expand Down
2 changes: 2 additions & 0 deletions marimo/_server/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def start(
allow_origins: Optional[tuple[str, ...]] = None,
auth_token: Optional[AuthToken],
redirect_console_to_browser: bool,
global_session: bool,
) -> None:
"""
Start the server.
Expand All @@ -102,6 +103,7 @@ def start(
cli_args=cli_args,
auth_token=auth_token,
redirect_console_to_browser=redirect_console_to_browser,
global_session=global_session,
)

log_level = "info" if development_mode else "error"
Expand Down
Loading