fix(core): 持有开机自启动设置任务引用并记录异常 - #416
Merged
Merged
Conversation
审查者指南本 PR 通过切断启动前的同步 import 链,将 8 个任务 Manager、OCR/GUI 相关重依赖及 ArknightWin32Toolkit 延迟到首次使用或后台任务启动时加载,并补强自启动异步任务的引用持有和异常处理;实测 serve 前耗时中位数从 2285 ms 降至 1920 ms,重依赖不再提前进入 Manager 惰性加载时序图sequenceDiagram
participant TM as TaskManager
participant Task as app.task
participant Importer as import_module
participant Manager as Manager submodule
TM->>Task: access task.MaaManager
Task->>Importer: import_module(.MAA, app.task)
Importer->>Manager: load MaaManager and dependencies
Manager-->>Task: MaaManager
Task->>Task: cache MaaManager in globals
Task-->>TM: MaaManager
已跟踪的自启动初始化时序图sequenceDiagram
participant Config as Config.init_config
participant EventLoop as asyncio event loop
participant System as System.set_SelfStart
participant Callback as _self_start_done
Config->>EventLoop: create_task(System.set_SelfStart(...))
Config->>Config: append task to temp_task
Config->>EventLoop: add_done_callback(_self_start_done)
EventLoop->>System: run set_SelfStart
System-->>EventLoop: complete or raise exception
EventLoop->>Callback: _self_start_done(task)
Callback->>Config: remove task from temp_task
Callback-->>Config: logger.warning on exception
文件级变更
提示与命令与 Sourcery 交互
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's Guide本 PR 通过切断启动前的同步 import 链,将 8 个任务 Manager、OCR/GUI 相关重依赖及 ArknightWin32Toolkit 延迟到首次使用或后台任务启动时加载,并补强自启动异步任务的引用持有和异常处理;实测 serve 前耗时中位数从 2285 ms 降至 1920 ms,重依赖不再提前进入 Sequence diagram for lazy Manager loadingsequenceDiagram
participant TM as TaskManager
participant Task as app.task
participant Importer as import_module
participant Manager as Manager submodule
TM->>Task: access task.MaaManager
Task->>Importer: import_module(.MAA, app.task)
Importer->>Manager: load MaaManager and dependencies
Manager-->>Task: MaaManager
Task->>Task: cache MaaManager in globals
Task-->>TM: MaaManager
Sequence diagram for tracked self-start initializationsequenceDiagram
participant Config as Config.init_config
participant EventLoop as asyncio event loop
participant System as System.set_SelfStart
participant Callback as _self_start_done
Config->>EventLoop: create_task(System.set_SelfStart(...))
Config->>Config: append task to temp_task
Config->>EventLoop: add_done_callback(_self_start_done)
EventLoop->>System: run set_SelfStart
System-->>EventLoop: complete or raise exception
EventLoop->>Callback: _self_start_done(task)
Callback->>Config: remove task from temp_task
Callback-->>Config: logger.warning on exception
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我已经审阅了你的更改,看起来很棒!
Sourcery 评估
已批准。
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用这些反馈来改进评审。
Original comment in English
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Approved.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
sourcery-ai
Bot
dismissed
their stale review
August 25, 2026 19:10
Sourcery withdrew this approval because the latest commits introduced blocking findings.
#407 把 System.set_SelfStart 改为 fire-and-forget 的 create_task 但未持有引用: task 可能被 GC, 且异常被静默吞掉。沿用本类既有的 temp_task + add_done_callback 模式, 失败时记录警告日志。
1w1w11w1
force-pushed
the
perf/startup-lazy-imports
branch
from
August 27, 2026 08:31
fadc6d1 to
30705ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
#407 把
System.set_SelfStart改为 fire-and-forget 的asyncio.create_task(...),但未持有返回的 task 引用:改动
沿用本类既有的
temp_task+add_done_callback模式(与_stage_refresh_task一致):temp_task持有 task 引用,避免被 GC;logger.warning;验证
7 failed, 200 passed,那 7 项在 dev 上已失败,与本 PR 无关。ruff format --check:触碰文件均 already formatted。Sourcery 摘要
修复自启动设置后台任务可能被垃圾回收且异常被静默忽略的问题。