Skip to content

Commit

Permalink
fix: solara run should only print url when the server is running
Browse files Browse the repository at this point in the history
If it takes a bit for a server to start, you will click the url
and it will not work.
  • Loading branch information
maartenbreddels committed Sep 5, 2024
1 parent d875ff5 commit 38f268d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions solara/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from enum import Enum
from pathlib import Path

import rich
import rich_click as click
import uvicorn
from rich import print as rprint
Expand All @@ -18,6 +17,7 @@
import solara
from solara.server import settings
import solara.server.threaded
import solara.server.server

from .server import telemetry

Expand Down Expand Up @@ -361,16 +361,19 @@ def run(
# # window.show()
# webview.start(debug=True)

def open_browser():
while not failed and (server is None or not server.started):
def check_server_started():
while not failed and (server is None or not server.started) or not solara.server.server.is_ready(url):
time.sleep(0.1)
if not failed:
webbrowser.open(url)
# remove the Solara server is starting ... line and print the url (in green)
print(f"\r\x1b[1;32mSolara server is running at {url}\x1b[0m")
if open:
webbrowser.open(url)

if open:
threading.Thread(target=open_browser, daemon=True).start()
threading.Thread(target=check_server_started, daemon=True).start()

rich.print(f"Solara server is starting at {url}")
# print in yellow that the server is starting
print("\x1b[1;33mSolara server is starting...\x1b[0m", end="", flush=True)

if log_level is not None:
LOGGING_CONFIG["loggers"]["solara"]["level"] = log_level.upper()
Expand All @@ -396,7 +399,7 @@ def open_browser():
settings.main.tracer = tracer
settings.main.timing = timing
items = (
"theme_variant_user_selectable dark theme_variant theme_loader use_pdb server open_browser open url failed dev tracer"
"theme_variant_user_selectable dark theme_variant theme_loader use_pdb server check_server_started open url failed dev tracer"
" timing ssg search check_version production".split()
)
for item in items:
Expand Down

0 comments on commit 38f268d

Please sign in to comment.