Skip to content

Commit

Permalink
fix: avoid hangups/delay when checking pypi version at startup (#855)
Browse files Browse the repository at this point in the history
* Add timeout to pypi version request, preventing undue hangups on startup

* never delay, only show outdated after server is started

* revert to original plan, but execute in a thread, and use mutex to avoid garbled printing

---------

Co-authored-by: Maarten A. Breddels <[email protected]>
  • Loading branch information
ntjess and maartenbreddels authored Dec 13, 2024
1 parent e2ad53d commit acfb977
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions solara/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from .server import telemetry

print_mutex = threading.Lock()

try:
from solara_enterprise.ssg import ssg_crawl
except ImportError:
Expand Down Expand Up @@ -75,13 +77,15 @@ def _check_version():
import requests

try:
response = requests.get("https://pypi.org/pypi/solara/json")
response = requests.get("https://pypi.org/pypi/solara/json", timeout=0.5)
latest_version = response.json()["info"]["version"]
except: # noqa: E722
# in case of a firewall, or timeout, we just abort
return
if latest_version != solara.__version__:
print(f"New version of Solara available: {latest_version}. You have {solara.__version__}. Please upgrade using:") # noqa: T201
print(f'\t$ pip install "solara=={latest_version}"') # noqa: T201
with print_mutex:
print(f"New version of Solara available: {latest_version}. You have {solara.__version__}. Please upgrade using:") # noqa: T201
print(f'\t$ pip install "solara=={latest_version}"') # noqa: T201


def find_all_packages_paths():
Expand Down Expand Up @@ -306,7 +310,7 @@ def run(
print("solara: --reload is deprecated, use --auto-restart/-a instead", file=sys.stderr) # noqa: T201
auto_restart = reload
if check_version:
_check_version()
threading.Thread(target=_check_version, daemon=True).run()

# uvicorn calls it reload, we call it auto restart
reload = auto_restart
Expand Down Expand Up @@ -390,7 +394,8 @@ def open_browser():
if open and not qt:
threading.Thread(target=open_browser, daemon=True).start()

rich.print(f"Solara server is starting at {url}")
with print_mutex:
rich.print(f"Solara server is starting at {url}")

if log_level is not None:
LOGGING_CONFIG["loggers"]["solara"]["level"] = log_level.upper()
Expand Down

0 comments on commit acfb977

Please sign in to comment.