Skip to main content

非阻塞后台进程管理工具,解决 Kiro IDE 中服务启动阻塞问题

Project description

Kiro Process Manager

PyPI version Python Support License: MIT

非阻塞后台进程管理工具,专为解决 Kiro IDE 中启动长期运行服务时的阻塞问题而设计。

问题背景

在使用 Kiro IDE 时,当需要启动长期运行的后台服务(如 uvicorn、redis-server 等)并随后运行测试时,Kiro 会因为同步等待进程退出而无限阻塞,导致后续命令无法执行。

解决方案

Kiro Process Manager 提供了一个简单而有效的解决方案,可以在 Kiro 中实现非阻塞的后台服务管理。

安装

pip install kiro-process-manager

快速开始

1. 初始化 Kiro 项目(推荐)

如果你在 Kiro 项目中使用,建议先运行初始化命令:

kiro-pm init

这会在当前目录创建 .kiro/steering/process-manager-tool.md 文件,让 Kiro 自动识别这个工具。

2. 基本用法

# 启动后台服务
kiro-pm start myapp "uvicorn main:app --port 8000"

# 等待服务就绪
kiro-pm wait-healthy 8000

# 查看运行的进程
kiro-pm list

# 停止服务
kiro-pm stop myapp

完整工作流(解决原始问题)

在 Kiro 中执行:

kiro-pm start api "uvicorn main:app --host 0.0.0.0 --port 8000" && kiro-pm wait-healthy 8000 30 && pytest tests/integration/ && kiro-pm stop api

高级用法

# 并行运行多个服务
kiro-pm start api "uvicorn main:app --port 8000"
kiro-pm start redis "redis-server --port 6379"
kiro-pm wait-healthy 8000
kiro-pm wait-healthy 6379

# 运行测试
pytest tests/integration/

# 清理所有服务
kiro-pm cleanup

功能特性

  • 非阻塞启动: 后台服务不会阻塞后续命令
  • 健康检查: 等待端口就绪后再执行测试
  • 进程管理: 启动、停止、列表、清理功能
  • 跨平台: 支持 Windows/Linux/macOS
  • 持久化: 进程信息保存到文件,支持会话恢复
  • 错误处理: 完善的异常处理和超时机制

命令参考

# 初始化 Kiro 项目
kiro-pm init

# 启动进程
kiro-pm start <name> <command>

# 停止进程
kiro-pm stop <name> [--force]

# 列出所有进程
kiro-pm list

# 等待端口就绪
kiro-pm wait-healthy <port> [--timeout SECONDS] [--host HOST]

# 清理所有进程
kiro-pm cleanup

使用场景

  1. Web 应用测试: 启动 FastAPI/Django 应用,运行集成测试
  2. 微服务测试: 同时启动多个服务,运行端到端测试
  3. 数据库测试: 启动 Redis/PostgreSQL,运行数据相关测试
  4. 前端开发: 同时启动前后端服务进行开发调试

技术原理

  • 使用 subprocess.Popen 非阻塞启动进程
  • 进程信息持久化到 JSON 文件
  • 通过 socket 连接检查端口健康状态
  • 支持优雅停止和强制终止
  • 跨平台进程管理(Windows 使用 taskkill,Unix 使用 signal)

开发

本地安装

git clone https://github.com/yourusername/kiro-process-manager.git
cd kiro-process-manager
pip install -e .

运行测试

# 测试基本功能
kiro-pm start test "python -m http.server 8080"
kiro-pm wait-healthy 8080
kiro-pm list
kiro-pm stop test

贡献

欢迎提交 Issue 和 Pull Request 来改进这个解决方案。

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kiro_process_manager-1.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kiro_process_manager-1.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file kiro_process_manager-1.1.1.tar.gz.

File metadata

  • Download URL: kiro_process_manager-1.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for kiro_process_manager-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2e47a3f89a35cfa3ec1ab904a8567077c4d08bafa4bb4cb2bd27c2dfef06499d
MD5 1929c545e70f3398d9468d329eea33fd
BLAKE2b-256 5ca65d26633423d67d1f2f3763411b5ead413f1f586e437b6eae36df9f8fdddc

See more details on using hashes here.

File details

Details for the file kiro_process_manager-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for kiro_process_manager-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9ef7a8296473f9bbb05afd9b08f5003687812bedd668521e518351432a5af39
MD5 def25e0b81a553a198a4422b9942d834
BLAKE2b-256 7e30c2957bf1feb8bf9b6151e86f78f69e2bc4ffbae56332d14d99060d4142df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page