Skip to content

Commit b718f53

Browse files
authored
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.
2 parents c7daa1d + 3244e3b commit b718f53

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "langflow"
3-
version = "0.6.5a2"
3+
version = "0.6.5a3"
44
description = "A Python package with a built-in web application"
55
authors = ["Logspace <[email protected]>"]
66
maintainers = [

src/backend/langflow/__main__.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
import multiprocessing
21
import platform
32
import socket
43
import sys
5-
import time
6-
import webbrowser
74
from pathlib import Path
85
from typing import Optional
96

10-
import httpx
117
import typer
128
from dotenv import load_dotenv
13-
from multiprocess import Process, cpu_count # type: ignore
9+
from multiprocess import cpu_count # type: ignore
1410
from rich import box
1511
from rich import print as rprint
1612
from rich.console import Console
1713
from rich.panel import Panel
1814
from rich.table import Table
15+
from sqlmodel import select
1916

2017
from langflow.main import setup_app
21-
from langflow.services.deps import get_settings_service
22-
from langflow.services.utils import initialize_settings_service
18+
from langflow.services.database.utils import session_getter
19+
from langflow.services.deps import get_db_service, get_settings_service
20+
from langflow.services.utils import initialize_services, initialize_settings_service
2321
from langflow.utils.logger import configure, logger
2422

2523
console = Console()
@@ -211,28 +209,12 @@ def run(
211209
run_on_windows(host, port, log_level, options, app)
212210
else:
213211
# Run using gunicorn on Linux
214-
run_on_mac_or_linux(host, port, log_level, options, platform.system(), open_browser)
212+
run_on_mac_or_linux(host, port, log_level, options, app)
215213

216214

217-
def run_on_mac_or_linux(host, port, log_level, options, system, open_browser=True):
218-
if system == "Darwin":
219-
ctx = multiprocessing.get_context("spawn")
220-
webapp_process = ctx.Process(target=run_langflow, args=(host, port, log_level, options))
221-
else:
222-
webapp_process = Process(target=run_langflow, args=(host, port, log_level, options))
223-
webapp_process.start()
224-
status_code = 0
225-
while status_code != 200:
226-
try:
227-
status_code = httpx.get(f"http://{host}:{port}/health").status_code
228-
229-
except Exception:
230-
time.sleep(1)
231-
215+
def run_on_mac_or_linux(host, port, log_level, options, app):
232216
print_banner(host, port)
233-
if open_browser:
234-
webbrowser.open(f"http://{host}:{port}")
235-
webapp_process.join()
217+
run_langflow(host, port, log_level, options, app)
236218

237219

238220
def run_on_windows(host, port, log_level, options, app):
@@ -302,7 +284,7 @@ def print_banner(host, port):
302284
rprint(panel)
303285

304286

305-
def run_langflow(host, port, log_level, options):
287+
def run_langflow(host, port, log_level, options, app):
306288
"""
307289
Run Langflow server on localhost
308290
"""
@@ -315,12 +297,10 @@ def run_langflow(host, port, log_level, options):
315297
import uvicorn
316298

317299
uvicorn.run(
318-
"langflow.main:create_app",
319-
factory=True,
300+
app,
320301
host=host,
321302
port=port,
322303
log_level=log_level,
323-
workers=options["workers"],
324304
)
325305
else:
326306
from langflow.server import LangflowApplication

0 commit comments

Comments
 (0)