Refactor run_on_mac_or_linux function and remove unused imports (#1335)
This pull request refactors the run_on_mac_or_linux function by removing unused imports and updating the function signature. This improves the code readability and maintainability.
This commit is contained in:
commit
b718f53419
2 changed files with 11 additions and 31 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "langflow"
|
name = "langflow"
|
||||||
version = "0.6.5a2"
|
version = "0.6.5a3"
|
||||||
description = "A Python package with a built-in web application"
|
description = "A Python package with a built-in web application"
|
||||||
authors = ["Logspace <contact@logspace.ai>"]
|
authors = ["Logspace <contact@logspace.ai>"]
|
||||||
maintainers = [
|
maintainers = [
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,23 @@
|
||||||
import multiprocessing
|
|
||||||
import platform
|
import platform
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import webbrowser
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import httpx
|
|
||||||
import typer
|
import typer
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from multiprocess import Process, cpu_count # type: ignore
|
from multiprocess import cpu_count # type: ignore
|
||||||
from rich import box
|
from rich import box
|
||||||
from rich import print as rprint
|
from rich import print as rprint
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
|
from sqlmodel import select
|
||||||
|
|
||||||
from langflow.main import setup_app
|
from langflow.main import setup_app
|
||||||
from langflow.services.deps import get_settings_service
|
from langflow.services.database.utils import session_getter
|
||||||
from langflow.services.utils import initialize_settings_service
|
from langflow.services.deps import get_db_service, get_settings_service
|
||||||
|
from langflow.services.utils import initialize_services, initialize_settings_service
|
||||||
from langflow.utils.logger import configure, logger
|
from langflow.utils.logger import configure, logger
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
@ -211,28 +209,12 @@ def run(
|
||||||
run_on_windows(host, port, log_level, options, app)
|
run_on_windows(host, port, log_level, options, app)
|
||||||
else:
|
else:
|
||||||
# Run using gunicorn on Linux
|
# Run using gunicorn on Linux
|
||||||
run_on_mac_or_linux(host, port, log_level, options, platform.system(), open_browser)
|
run_on_mac_or_linux(host, port, log_level, options, app)
|
||||||
|
|
||||||
|
|
||||||
def run_on_mac_or_linux(host, port, log_level, options, system, open_browser=True):
|
def run_on_mac_or_linux(host, port, log_level, options, app):
|
||||||
if system == "Darwin":
|
|
||||||
ctx = multiprocessing.get_context("spawn")
|
|
||||||
webapp_process = ctx.Process(target=run_langflow, args=(host, port, log_level, options))
|
|
||||||
else:
|
|
||||||
webapp_process = Process(target=run_langflow, args=(host, port, log_level, options))
|
|
||||||
webapp_process.start()
|
|
||||||
status_code = 0
|
|
||||||
while status_code != 200:
|
|
||||||
try:
|
|
||||||
status_code = httpx.get(f"http://{host}:{port}/health").status_code
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
print_banner(host, port)
|
print_banner(host, port)
|
||||||
if open_browser:
|
run_langflow(host, port, log_level, options, app)
|
||||||
webbrowser.open(f"http://{host}:{port}")
|
|
||||||
webapp_process.join()
|
|
||||||
|
|
||||||
|
|
||||||
def run_on_windows(host, port, log_level, options, app):
|
def run_on_windows(host, port, log_level, options, app):
|
||||||
|
|
@ -302,7 +284,7 @@ def print_banner(host, port):
|
||||||
rprint(panel)
|
rprint(panel)
|
||||||
|
|
||||||
|
|
||||||
def run_langflow(host, port, log_level, options):
|
def run_langflow(host, port, log_level, options, app):
|
||||||
"""
|
"""
|
||||||
Run Langflow server on localhost
|
Run Langflow server on localhost
|
||||||
"""
|
"""
|
||||||
|
|
@ -315,12 +297,10 @@ def run_langflow(host, port, log_level, options):
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"langflow.main:create_app",
|
app,
|
||||||
factory=True,
|
|
||||||
host=host,
|
host=host,
|
||||||
port=port,
|
port=port,
|
||||||
log_level=log_level,
|
log_level=log_level,
|
||||||
workers=options["workers"],
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
from langflow.server import LangflowApplication
|
from langflow.server import LangflowApplication
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue