Skip to content

fix(s11): support background cleanup on Windows - #563

Open
yee211 wants to merge 1 commit into
shareAI-lab:mainfrom
yee211:codex/fix-s11-windows-background-cleanup
Open

yee211 wants to merge 1 commit into
shareAI-lab:mainfrom
yee211:codex/fix-s11-windows-background-cleanup

Conversation

@yee211

@yee211 yee211 commented Sep 8, 2026

Copy link
Copy Markdown

Related to #65

问题

在 Windows 上运行 s11 后台任务示例时,_stop_process_group() 会调用 POSIX 专属的 os.killpgsignal.SIGKILL

清理过程发生在 finally 中,因此这里的异常会覆盖原本已经成功的命令结果,导致前台和后台命令都被错误标记为失败,也无法正常观察本章要演示的后台任务生命周期。

修改内容

  • Windows 上使用 Popen.terminate(),超时后使用 Popen.kill() 清理 Shell 进程。
  • 保留 POSIX 平台原有的进程组清理逻辑。
  • 增加 Windows 清理逻辑测试。
  • 增加后台任务完整生命周期测试。
  • 将三种语言 README 中的测试命令改为 Windows、Linux 和 macOS 均可运行的形式。
  • 修正 npm 示例的项目路径为 web/package.json
  • 同步更新网站生成的文档数据。

教学行为保持不变

修复后仍然可以观察本章的三个重点:

  1. 显式设置 run_in_background 后,命令被送到后台。
  2. 工具立即返回 bg_id,前台可以继续执行其他工具。
  3. 后台任务完成后,在后续轮次以 <task_notification> 格式收集结果,并且只收集一次。

验证

  • 在 Windows 11 / Python 3.13 环境手动验证三条教学示例通过。
  • python -m pytest tests/test_background_tasks.py tests/test_chapter_readmes.py -q
    • 9 tests passed
  • npm --prefix web run build
    • Build passed

与 Issue #65 的关系

本 PR 解决的是 #65s11 后台任务清理和教学示例的 Windows 兼容问题

它不代表整个仓库在 Windows 上的全部兼容问题已经解决,因此使用 Related to #65,不自动关闭该 Issue。

AI assistance

本 PR 在问题诊断、测试设计和代码检查过程中使用了 OpenAI Codex 辅助。修复内容已由我在 Windows 环境中手动复现、审查并验证。

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