diff --git a/marimo/_cli/cli.py b/marimo/_cli/cli.py index b443b24db12..2d899e91bde 100644 --- a/marimo/_cli/cli.py +++ b/marimo/_cli/cli.py @@ -354,6 +354,7 @@ def edit( base_url=base_url, allow_origins=allow_origins, redirect_console_to_browser=True, + global_session=True, ) @@ -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, @@ -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, ...], @@ -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, ) diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.py index 32b9c6cb923..0aa962e6abd 100644 --- a/marimo/_server/sessions.py +++ b/marimo/_server/sessions.py @@ -661,6 +661,7 @@ def __init__( cli_args: SerializedCLIArgs, auth_token: Optional[AuthToken], redirect_console_to_browser: bool = False, + global_session: bool = False, ) -> None: self.file_router = file_router self.mode = mode @@ -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: @@ -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 diff --git a/marimo/_server/start.py b/marimo/_server/start.py index 28abe060a77..64dd20db97c 100644 --- a/marimo/_server/start.py +++ b/marimo/_server/start.py @@ -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. @@ -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"