Skip to content

feature/sort_mode_handman123#1677

Open
handman123 wants to merge 5 commits into
runhey:devfrom
handman123:feature/sort_module_handman123
Open

feature/sort_mode_handman123#1677
handman123 wants to merge 5 commits into
runhey:devfrom
handman123:feature/sort_module_handman123

Conversation

@handman123

@handman123 handman123 commented Jul 13, 2026

Copy link
Copy Markdown

增加排队模式

(该功能只在mac上测试过,win电脑坏了一直没修,不知道在win上有没有其它问题)

image

如果需要脚本同时管理多个账号(多开),但服务器或者个人电脑性能不够(无法稳定流畅的同时运行多个模拟器),就会出现严重卡顿。不如将原本的并行执行改为串行执行

image

多个实例按照先来先服务的调度策略依次执行。

流程:

  1. 启用排队模式的实例启动后,首先尝试获取执行权;
  2. 获取成功的实例可以启动模拟器并执行任务,同时启动心跳线程持续向共享状态文件汇报存活状态;
  3. 其他实例进入等待队列,每 30 秒检查一次执行权是否释放;
  4. 持有执行权的实例完成所有待执行任务,且下一个任务在 queue_idle_threshold 分钟内不触发时,主动释放执行权;
  5. 执行权自动移交给等待队列中的下一个实例,继续步骤 2。

说明:不参与排队的实例,按照原逻辑执行。

应用场景:
想要多开且电脑性能不够

未来扩展:

  1. 勾选queue_mode选项的实例集合,只能同一时刻执行一个模拟器,但如果电脑性能更好一些,同一时刻完全可以带多个模拟器。因此,后续可将互斥锁升级为信号量,允许配置最大并行数 N,同一时刻最多 N 个实例同时执行。
  2. 当前所有参与排队的实例,都是公平竞争锁,实际上大部分用户可能只有一个主号或者两个主号,其余的都是小号,那完全可以给主号更高的优先级,让其可以插队获取执行权力。

Summary by Sourcery

引入跨进程的排队机制,使多个脚本实例能够顺序使用模拟器,从而避免并发加载问题。

新特性:

  • 添加 queue_mode 优化选项和空闲阈值配置,用于控制多实例间的串行执行。
  • 实现 InstanceGuard 组件,通过共享状态文件和心跳监控来协调执行令牌。
  • 将队列令牌的获取和释放集成到任务调度、空闲等待和运行流程中,在启用 queue_mode 时强制执行“先到先执行”的顺序。

错误修复:

  • 在 ADB 操作中遇到 EmulatorNotRunningError 时,通过重启模拟器并重新连接 ADB 来恢复。

增强项:

  • 在配置管理器中对发现的脚本配置文件进行确定性排序,以提供稳定的顺序。
Original summary in English

Summary by Sourcery

Introduce a cross-process queueing mechanism so that multiple script instances can serialize emulator usage and avoid concurrent load issues.

New Features:

  • Add a queue_mode optimization option and idle threshold configuration to control serialized execution across instances.
  • Implement an InstanceGuard component that coordinates execution tokens via a shared state file and heartbeat monitoring.
  • Integrate queue token acquisition and release into task scheduling, idle waiting, and run flow to enforce first-come-first-served execution when queue_mode is enabled.

Bug Fixes:

  • Recover from EmulatorNotRunningError in ADB operations by restarting the emulator and reconnecting ADB.

Enhancements:

  • Sort discovered script configuration files deterministically in the config manager to provide a stable ordering.

@handman123 handman123 changed the title feature/sort_module_handman123 feature/sort_mode_handman123 Jul 13, 2026

@sourcery-ai sourcery-ai 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.

嗨,我已经审阅了你的改动,一切看起来都很棒!


Sourcery 对开源项目是免费的——如果你喜欢我们的审查,请考虑分享它 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进审查质量。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@runhey

runhey commented Jul 13, 2026

Copy link
Copy Markdown
Owner

很好的需求!

@runhey

runhey commented Jul 13, 2026

Copy link
Copy Markdown
Owner

不过我第一个想法是把模拟器当作调度任务的需求资源,

@runhey

runhey commented Jul 13, 2026

Copy link
Copy Markdown
Owner

那如果多个账号,同时同一个时间点,都有一个很重要的任务需要执行,这种好像就满足不了。不过好像问题不大

@handman123

Copy link
Copy Markdown
Author

不过我第一个想法是把模拟器当作调度任务的需求资源,

我想了想,这样确实更好,可以做一个“模拟器池”的这么一个模型,类似线程池,需要执行任务从池子中获取空闲模拟器。然后再配合账号切换的功能,就完全可以实现模拟器资源化,不用把配置和模拟器绑定。但是目前的这个已经满足我的需求了,我不咋想再折腾了😂

@handman123

Copy link
Copy Markdown
Author

那如果多个账号,同时同一个时间点,都有一个很重要的任务需要执行,这种好像就满足不了。不过好像问题不大

这个好说,普通用户(不是脚本代肝的商人),最多就只有两个主号,再加一个优先级的功能,让主号优先执行,至于小号,只要在活动截止之前完成就行了。我是只有一个主号,所以主号不开“排队模式”,只有三个小号才需要竞争执行权,所以对我来说问题不大。

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.

2 participants