Skip to content

feat: add graceful shutdown with signal handler#114

Open
coolxll wants to merge 1 commit intocnlimiter:masterfrom
coolxll:feat/graceful-shutdown
Open

feat: add graceful shutdown with signal handler#114
coolxll wants to merge 1 commit intocnlimiter:masterfrom
coolxll:feat/graceful-shutdown

Conversation

@coolxll
Copy link
Copy Markdown

@coolxll coolxll commented Mar 29, 2026

问题

在 Windows 下运行注册任务时,Ctrl+C 经常无法停止进程。原因:

  1. \curl_cffi\ 是 C 扩展,HTTP 请求期间信号处理器不会被调用
  2. 线程池隔离,任务在子线程运行,信号发送到主线程
  3. 默认 HTTP 超时 30 秒,阻塞时间长

改动

  1. 添加信号处理器 (\src/web/app.py)

    • 第一次 Ctrl+C:取消所有运行中任务并退出
    • 第二次 Ctrl+C:强制退出
    • 支持 SIGINT 和 SIGTERM
  2. 降低默认 HTTP 超时 (\src/core/http_client.py)

    • 30 秒 → 10 秒
    • 让 Ctrl+C 响应更快

测试

  • Windows 10 + Python 3.13
  • 启动任务后按 Ctrl+C,进程在 10 秒内退出
  • 双击 Ctrl+C 立即强制退出

- Add SIGINT/SIGTERM signal handler for graceful exit
- Cancel all running tasks on shutdown
- Reduce default HTTP timeout from 30s to 10s for faster Ctrl+C response
- Support double Ctrl+C for forced exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant