fix: set workers to 0 if env variable is not set
This commit is contained in:
parent
a5895352de
commit
9942efdf6d
1 changed files with 16 additions and 5 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
|
||||||
from langflow_backend.main import create_app
|
from langflow_backend.main import create_app
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
|
@ -8,6 +11,18 @@ from pathlib import Path
|
||||||
from langflow_backend.server import LangflowApplication
|
from langflow_backend.server import LangflowApplication
|
||||||
|
|
||||||
|
|
||||||
|
def get_number_of_workers(workers=None):
|
||||||
|
if workers is None:
|
||||||
|
workers = (
|
||||||
|
int(os.environ.get("OBJC_DISABLE_INITIALIZE_FORK_SAFETY", "0") == "YES")
|
||||||
|
if platform.system() == "Darwin"
|
||||||
|
else 1
|
||||||
|
)
|
||||||
|
elif workers == -1:
|
||||||
|
workers = (multiprocessing.cpu_count() * 2) + 1
|
||||||
|
return workers
|
||||||
|
|
||||||
|
|
||||||
def serve(
|
def serve(
|
||||||
workers: int = None,
|
workers: int = None,
|
||||||
timeout: int = None,
|
timeout: int = None,
|
||||||
|
|
@ -21,17 +36,13 @@ def serve(
|
||||||
StaticFiles(directory=static_files_dir, html=True),
|
StaticFiles(directory=static_files_dir, html=True),
|
||||||
name="static",
|
name="static",
|
||||||
)
|
)
|
||||||
if not workers:
|
|
||||||
workers = 1
|
|
||||||
elif workers == -1:
|
|
||||||
workers = (multiprocessing.cpu_count() * 2) + 1
|
|
||||||
|
|
||||||
if not timeout:
|
if not timeout:
|
||||||
timeout = 60
|
timeout = 60
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"bind": "127.0.0.1:5003",
|
"bind": "127.0.0.1:5003",
|
||||||
"workers": workers,
|
"workers": get_number_of_workers(workers),
|
||||||
"worker_class": "uvicorn.workers.UvicornWorker",
|
"worker_class": "uvicorn.workers.UvicornWorker",
|
||||||
"timeout": timeout,
|
"timeout": timeout,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue