Skip to content

feat: 支持非阻塞运行脚本 - #71

Closed
LevelDownRefine wants to merge 1 commit into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/nonblock
Closed

feat: 支持非阻塞运行脚本#71
LevelDownRefine wants to merge 1 commit into
OneDragon-Anything:mainfrom
LevelDownRefine:lvdown/nonblock

Conversation

@LevelDownRefine

@LevelDownRefine LevelDownRefine commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

支持非阻塞运行脚本,使得可以后台运行部分脚本

Summary by CodeRabbit

  • 新功能

    • 新增“阻塞运行”选项,可在脚本配置中保存并控制运行方式。
    • 支持按配置顺序运行脚本链,并在完成后报告启动成功数量及失败脚本。
    • 运行期间会禁用“运行全部”按钮,避免重复启动。
  • 改进

    • 脚本启动提示会显示当前运行模式。
    • 阻塞模式下可等待脚本进程结束,并反馈执行结果。

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

新增 block 配置及编辑开关,支持终端阻塞等待;单脚本调试和脚本链运行均传递该配置,脚本链改为线程顺序启动并回传成功、失败结果。

Changes

阻塞运行流程

Layer / File(s) Summary
配置与终端启动契约
src/script_chainer/config/script_config.py, src/script_chainer/utils/process_utils.py
ScriptConfig 新增默认值为 Trueblock 字段;launch_in_terminal 支持阻塞等待真实子进程结束。
脚本编辑与调试接入
src/script_chainer/gui/page/script_edit_interface.py, src/script_chainer/gui/page/script_setting_cards.py
编辑界面同步阻塞开关与配置值,单脚本调试启动时传递阻塞模式并更新提示文本。
脚本链线程执行与结果回传
src/script_chainer/gui/page/script_setting_interface.py
ChainRunner 按顺序启动启用脚本,汇总失败脚本,并通过信号更新界面状态和提示。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ScriptSettingRootInterface
  participant ChainRunner
  participant launch_in_terminal
  participant ScriptProcess
  ScriptSettingRootInterface->>ChainRunner: 提交启用脚本规格
  ChainRunner->>launch_in_terminal: 传递 block 并启动脚本
  launch_in_terminal->>ScriptProcess: 创建终端子进程
  ScriptProcess-->>ChainRunner: 返回执行状态
  ChainRunner-->>ScriptSettingRootInterface: 回传成功数量和失败列表
Loading

Possibly related PRs

Suggested reviewers: shadowlemoon

Poem

我是小兔,带来阻塞开关,
终端启动,等待不慌。
脚本排队,线程奔忙,
成功失败,清楚回响。
新配置落地,胡萝卜真香!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次变更的核心:支持脚本非阻塞运行。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/script_chainer/gui/page/script_setting_cards.py (1)

161-168: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

不要在 GUI 线程中等待阻塞调试进程。

block=True 会同步等待脚本退出,导致整个界面冻结;且脚本以非零状态退出后仍会显示“启动成功”。请将启动/等待移入工作线程,并在完成回调中根据 returncode 显示完成或失败状态。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/script_chainer/gui/page/script_setting_cards.py` around lines 161 - 168,
Update the debug-launch flow around launch_in_terminal so it never waits
synchronously on the GUI thread when self.config.block is true. Move process
startup and waiting into a worker thread, then use the completion callback to
inspect the process returncode and show a success message only for a zero exit
status, otherwise show a failure status; keep non-blocking launches responsive
and avoid reporting success before completion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/script_chainer/gui/page/script_setting_interface.py`:
- Around line 235-238: Update the specs construction in the relevant script
settings method to use cfg.script_display_name instead of cfg.display_name,
ensuring failure messages always include the script filename or fallback display
name while preserving the existing enabled-script filtering.

---

Outside diff comments:
In `@src/script_chainer/gui/page/script_setting_cards.py`:
- Around line 161-168: Update the debug-launch flow around launch_in_terminal so
it never waits synchronously on the GUI thread when self.config.block is true.
Move process startup and waiting into a worker thread, then use the completion
callback to inspect the process returncode and show a success message only for a
zero exit status, otherwise show a failure status; keep non-blocking launches
responsive and avoid reporting success before completion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 614dad46-33df-4c7e-9ca0-680fecdf5931

📥 Commits

Reviewing files that changed from the base of the PR and between 7d2bebe and beab14d.

📒 Files selected for processing (5)
  • src/script_chainer/config/script_config.py
  • src/script_chainer/gui/page/script_edit_interface.py
  • src/script_chainer/gui/page/script_setting_cards.py
  • src/script_chainer/gui/page/script_setting_interface.py
  • src/script_chainer/utils/process_utils.py

Comment on lines +235 to +238
specs = [
(i, cfg.block, cfg.display_name)
for i, cfg in enumerate(self.chosen_config.script_list)
if cfg.enabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

失败提示应使用始终可用的脚本显示名。

display_name 默认为空,默认脚本启动失败时会得到空白条目。请改用 cfg.script_display_name,以便错误提示包含文件名或回退名称。

-            (i, cfg.block, cfg.display_name)
+            (i, cfg.block, cfg.script_display_name)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
specs = [
(i, cfg.block, cfg.display_name)
for i, cfg in enumerate(self.chosen_config.script_list)
if cfg.enabled
specs = [
(i, cfg.block, cfg.script_display_name)
for i, cfg in enumerate(self.chosen_config.script_list)
if cfg.enabled
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/script_chainer/gui/page/script_setting_interface.py` around lines 235 -
238, Update the specs construction in the relevant script settings method to use
cfg.script_display_name instead of cfg.display_name, ensuring failure messages
always include the script filename or fallback display name while preserving the
existing enabled-script filtering.

@LevelDownRefine
LevelDownRefine marked this pull request as draft July 28, 2026 03:04
@LevelDownRefine

Copy link
Copy Markdown
Contributor Author

应该得写进launch_script

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