-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add SIGTERM handling and update typer
dependency
#4548
Conversation
2c8a925
to
e9bf62f
Compare
- Introduce signal handlers to manage SIGTERM and SIGINT for graceful server shutdown. - Update exception handling to ensure processes terminate properly and log shutdown events. - Modify server run logic to support signal-based shutdowns, improving reliability.
3ddeab0
to
b2975f1
Compare
CodSpeed Performance ReportMerging #4548 will degrade performances by 17.02%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Built image and ran docker stop <container>
and see shutdown:
~/Documents/langflow/langflow (update-typer ✗) docker run --init --rm -p 7860:7860 test:latest
Starting Langflow v1.0.19.post2...
/app/.venv/lib/python3.12/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)
/app/.venv/lib/python3.12/site-packages/langchain_community/retrievers/kendra.py:379: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
@validator("top_k")
╭───────────────────────────────────────────────────────────────────╮
│ Welcome to ⛓ Langflow │
│ │
│ │
│ Collaborate, and contribute at our GitHub Repo 🌟 │
│ │
│ We collect anonymous usage data to improve Langflow. │
│ You can opt-out by setting DO_NOT_TRACK=true in your environment. │
│ │
│ Access http://0.0.0.0:7860 │
╰───────────────────────────────────────────────────────────────────╯
Langflow shutdown complete
[11/12/24 21:14:41] ERROR 2024-11-12 21:14:41 - ERROR - __init__.py:1762
__init__ - Worker (pid:30) was
sent SIGTERM!
Though, sending SIGTERM to the uv process from make backend just terminates a local process. I think that's okay (though, not what I'd expect?)
(.venv) ~/Documents/langflow/langflow (update-typer ✗) make backend
Installing backend dependencies
Audited 452 packages in 0.67ms
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
Running backend respecting the .env file
uv run uvicorn \
--factory langflow.main:create_app \
--host 0.0.0.0 \
--port 7860 \
--reload \
--env-file .env \
--loop asyncio \
--workers 1
INFO: Will watch for changes in these directories: ['/Users/jordan.frazier/Documents/Langflow/langflow']
INFO: Loading environment from '.env'
INFO: Uvicorn running on http://0.0.0.0:7860 (Press CTRL+C to quit)
INFO: Started reloader process [78236] using WatchFiles
Starting Langflow v1.0.19.post2...
/Users/jordan.frazier/Documents/Langflow/langflow/.venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)
/Users/jordan.frazier/Documents/Langflow/langflow/.venv/lib/python3.11/site-packages/pydantic/_internal/_config.py:341: UserWarning: Valid config keys have changed in V2:
* 'schema_extra' has been renamed to 'json_schema_extra'
warnings.warn(message, UserWarning)
/Users/jordan.frazier/Documents/Langflow/langflow/.venv/lib/python3.11/site-packages/composio/client/http.py:20: DeprecationWarning: Inheritance class AsyncHttpClient from ClientSession is discouraged
class AsyncHttpClient(AsyncSession, logging.WithLogger):
make: *** [backend] Terminated: 15
edit: ^ is probably due to makefile process on top of uv
…#4548) * Update `typer` dependency to version 0.13.0 in `pyproject.toml` * refactor: Simplify exception handling in the CLI * Enhance lifespan function with clean shutdown and logging improvements * Add graceful shutdown handling for SIGTERM and SIGINT signals - Introduce signal handlers to manage SIGTERM and SIGINT for graceful server shutdown. - Update exception handling to ensure processes terminate properly and log shutdown events. - Modify server run logic to support signal-based shutdowns, improving reliability. --------- Co-authored-by: Nadir J <31660040+NadirJ@users.noreply.github.com>
This pull request includes several updates to the
src/backend/base/langflow/__main__.py
file to improve error handling and code readability, as well as a dependency update inpyproject.toml
.Improvements to error handling:
KeyboardInterrupt
andException
handling in therun
function to usetyper.Exit
for cleaner exits and added handling forSystemExit
to ensure the process is terminated gracefully.main
function call to log exceptions and exit gracefully usingtyper.Exit
.Code readability improvements:
langflow.services.database.models.folder.utils
andlangflow.services.database.models.api_key.crud
into single lines. [1] [2]Dependency updates:
typer
dependency version from0.12.0
to0.13.0
inpyproject.toml
.