From 80db6b910e84d9559de3b64ac560e698bf72ba85 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 21 Jul 2023 23:57:52 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.py):=20impo?= =?UTF-8?q?rt=20get=5Fnumber=5Fof=5Fworkers=20function=20from=20langflow.u?= =?UTF-8?q?tils.util=20module=20to=20fix=20NameError=20=F0=9F=94=A7=20fix(?= =?UTF-8?q?=5F=5Fmain=5F=5F.py):=20change=20default=20value=20of=20workers?= =?UTF-8?q?=20option=20to=20-1=20to=20indicate=20automatic=20calculation?= =?UTF-8?q?=20of=20number=20of=20workers=20=F0=9F=94=A7=20fix(=5F=5Fmain?= =?UTF-8?q?=5F=5F.py):=20remove=20unused=20import=20of=20cpu=5Fcount=20fro?= =?UTF-8?q?m=20multiprocess=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F?= =?UTF-8?q?.py):=20remove=20unused=20import=20of=20time=20module=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.py):=20remove=20unused=20im?= =?UTF-8?q?port=20of=20httpx=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F?= =?UTF-8?q?=5F.py):=20remove=20unused=20import=20of=20sys=20module=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.py):=20remove=20unused=20im?= =?UTF-8?q?port=20of=20os=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.p?= =?UTF-8?q?y):=20remove=20unused=20import=20of=20Path=20class=20from=20pat?= =?UTF-8?q?hlib=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.py):=20remo?= =?UTF-8?q?ve=20unused=20import=20of=20load=5Fdotenv=20function=20from=20d?= =?UTF-8?q?otenv=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.py):=20rem?= =?UTF-8?q?ove=20unused=20import=20of=20typer=20module=20=F0=9F=94=A7=20fi?= =?UTF-8?q?x(=5F=5Fmain=5F=5F.py):=20remove=20unused=20import=20of=20app?= =?UTF-8?q?=20object=20from=20typer=20module=20=F0=9F=94=A7=20fix(=5F=5Fma?= =?UTF-8?q?in=5F=5F.py):=20remove=20unused=20import=20of=20Optional=20type?= =?UTF-8?q?=20from=20typing=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F?= =?UTF-8?q?.py):=20remove=20unused=20import=20of=20Process=20class=20from?= =?UTF-8?q?=20multiprocess=20module=20=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.?= =?UTF-8?q?py):=20remove=20unused=20import=20of=20platform=20module=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(=5F=5Fmain=5F=5F.py):=20remove=20unused=20im?= =?UTF-8?q?port=20of=20update=5Fsettings=20function=20=F0=9F=94=A7=20fix(?= =?UTF-8?q?=5F=5Fmain=5F=5F.py):=20remove=20unused=20import=20of=20run=5Fl?= =?UTF-8?q?angflow=20function=20=F0=9F=94=A7=20fix(util.py):=20import=20lo?= =?UTF-8?q?gger=20from=20langflow.utils.logger=20module=20to=20fix=20NameE?= =?UTF-8?q?rror=20=F0=9F=94=A7=20fix(util.py):=20import=20cpu=5Fcount=20fr?= =?UTF-8?q?om=20multiprocess=20module=20to=20fix=20NameError=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(util.py):=20add=20default=20value=20of=20Non?= =?UTF-8?q?e=20to=20workers=20parameter=20in=20get=5Fnumber=5Fof=5Fworkers?= =?UTF-8?q?=20function=20to=20fix=20TypeError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 13 ++++--------- src/backend/langflow/utils/util.py | 9 +++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index 385e74932..63c5fe87f 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -2,7 +2,8 @@ import os import sys import time import httpx -from multiprocess import Process, cpu_count # type: ignore +from langflow.utils.util import get_number_of_workers +from multiprocess import Process # type: ignore import platform from pathlib import Path from typing import Optional @@ -20,12 +21,6 @@ from dotenv import load_dotenv app = typer.Typer() -def get_number_of_workers(workers=None): - if workers == -1: - workers = (cpu_count() * 2) + 1 - return workers - - def update_settings( config: str, cache: str, @@ -120,7 +115,7 @@ def serve( "127.0.0.1", help="Host to bind the server to.", envvar="LANGFLOW_HOST" ), workers: int = typer.Option( - 1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS" + -1, help="Number of worker processes.", envvar="LANGFLOW_WORKERS" ), timeout: int = typer.Option(60, help="Worker timeout in seconds."), port: int = typer.Option(7860, help="Port to listen on.", envvar="LANGFLOW_PORT"), @@ -298,7 +293,7 @@ def run_langflow(host, port, log_level, options, app): Run Langflow server on localhost """ try: - if platform.system() in ["Darwin", "Windows"]: + if platform.system() in ["Windows"]: # Run using uvicorn on MacOS and Windows # Windows doesn't support gunicorn # MacOS requires an env variable to be set to use gunicorn diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 0ee39b337..ce5f03bdf 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -8,6 +8,8 @@ from docstring_parser import parse # type: ignore from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS from langflow.utils import constants +from langflow.utils.logger import logger +from multiprocess import cpu_count def build_template_from_function( @@ -451,3 +453,10 @@ def add_options_to_field( value["options"] = options_map[class_name] value["list"] = True value["value"] = options_map[class_name][0] + + +def get_number_of_workers(workers=None): + if workers == -1 or workers is None: + workers = (cpu_count() * 2) + 1 + logger.debug(f"Number of workers: {workers}") + return workers