fix(ai-studio): keep worker thread alive until finished
This commit is contained in:
+23
-2
@@ -3,7 +3,7 @@ id: T-604
|
||||
title: AI工场拉取主图 QThread 生命周期闪退修复
|
||||
phase: 7
|
||||
deps: [T-591]
|
||||
status: TODO
|
||||
status: DONE
|
||||
created: 2026-07-11
|
||||
---
|
||||
|
||||
@@ -117,4 +117,25 @@ git diff --check
|
||||
|
||||
## 执行记录
|
||||
|
||||
待执行。
|
||||
- 2026-07-11:已完成。
|
||||
- 代码:
|
||||
- `app/gui/tabs/image_studio.py`:AI工场 `_start_worker()` 改为 `run_worker(..., start=False)` 后保存 `worker/thread`,连接 `thread.finished` 再清理引用,最后手动 `thread.start()`;`_finish_worker()` 不再提前置空 `self._running_thread`,避免 `QThread` 仍运行时被销毁。
|
||||
- `app/gui/tabs/image_studio.py`:新增 `_worker_error_handled` 与 `_handle_finished_error()`,收敛 `failed` + `finished(ok=False)` 双信号路径,避免失败重复弹窗/重复日志。
|
||||
- `app/gui/tabs/image_studio.py`:`pull_main_images()` 改为使用当前账号下拉和商品ID输入框,不再被旧 `current_project` 覆盖。
|
||||
- 测试:
|
||||
- `tests/test_gui.py`:新增 AI工场线程生命周期测试,确认 `_finish_worker()` 后线程引用仍保留,只有 `thread.finished` 后才清理。
|
||||
- `tests/test_gui.py`:新增失败只处理一次测试,覆盖 `failed` 后又收到 `finished(ok=False)` 不重复弹窗。
|
||||
- `tests/test_gui.py`:新增拉取主图参数测试,覆盖当前输入商品ID不同于旧项目时仍传入当前输入。
|
||||
- 验证:
|
||||
- 主工作区定向验证通过:
|
||||
- `py -3.10 -m unittest tests.test_gui.GuiTests.test_image_studio_worker_thread_is_kept_until_thread_finished tests.test_gui.GuiTests.test_image_studio_worker_failure_is_handled_once tests.test_gui.GuiTests.test_image_studio_pull_main_images_uses_current_item_input`
|
||||
- `python -m ruff check app tests main.py`
|
||||
- `py -3.10 -m compileall app main.py`
|
||||
- `py -3.10 -m unittest tests.test_gui.GuiTests.test_image_studio_tab_builds_project_pool_and_template_controls tests.test_gui.GuiTests.test_image_studio_generation_log_uses_cmhub_tier_summary tests.test_gui.GuiTests.test_image_studio_worker_thread_is_kept_until_thread_finished tests.test_gui.GuiTests.test_image_studio_worker_failure_is_handled_once tests.test_gui.GuiTests.test_image_studio_pull_main_images_uses_current_item_input`
|
||||
- `git diff --check -- app\gui\tabs\image_studio.py tests\test_gui.py docs\tasks\T-604.md`
|
||||
- 主工作区全量 `py -3.10 -m unittest discover -s tests` 因既有未提交默认提示词改动失败 3 个用例,失败内容为 `papa1` 与乱码 `默认` 文件名不一致,不属于 T-604。
|
||||
- 为满足提交前全绿验证,已在临时干净 worktree `D:\chengma\cmshopee-t604-verify` 只应用 T-604 diff 后通过:
|
||||
- `python -m ruff check app tests main.py`
|
||||
- `py -3.10 -m compileall app main.py`
|
||||
- `py -3.10 -m unittest discover -s tests`(378 tests)
|
||||
- `git diff --check -- app\gui\tabs\image_studio.py tests\test_gui.py docs\tasks\T-604.md`
|
||||
|
||||
Reference in New Issue
Block a user