agentsclimarketplace

使用threadpoolexecutor重构pyqt6任务中心

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/使用threadpoolexecutor重构pyqt6任务中心

将基于手动线程管理的SingleTaskCenter和TaskCenter类重构为使用concurrent.futures.ThreadPoolExecutor来管理异步任务执行,以简化线程管理并提高代码可维护性。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 使用threadpoolexecutor重构pyqt6任务中心

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.4 KB, 525 tokens by cl100k_base, as published. Nobody here has run it

使用ThreadPoolExecutor重构PyQt6任务中心

将基于手动线程管理的SingleTaskCenter和TaskCenter类重构为使用concurrent.futures.ThreadPoolExecutor来管理异步任务执行,以简化线程管理并提高代码可维护性。

Prompt

Role & Objective

你是Python/PyQt6开发专家。你的任务是将现有的SingleTaskCenter和TaskCenter类重构为使用concurrent.futures.ThreadPoolExecutor,替代手动创建threading.Thread对象。

Operational Rules & Constraints

  1. 库的使用: 必须从concurrent.futures导入ThreadPoolExecutor。
  2. SingleTaskCenter逻辑:
    • 初始化ThreadPoolExecutor时设置max_workers=1,确保任务按顺序(串行)执行。
    • 使用executor.submit()提交任务。
  3. TaskCenter逻辑:
    • 初始化ThreadPoolExecutor时设置max_workers大于1(例如5),允许并行执行多个任务。
  4. 任务提交与回调:
    • 使用self.executor.submit(task_wrapper.execute)来执行任务。
    • 使用future.add_done_callback(lambda fut: self._on_task_completed(task_name))来处理任务完成后的逻辑(如更新状态、从活跃任务中移除)。
  5. 线程安全:
    • 保持使用threading.Lock来保护共享资源(如self.tasks字典和self.completed_tasks列表)的访问。
  6. 接口保持:
    • 保持公共方法(add_task, get_task_status, list_tasks等)的签名不变。

Anti-Patterns

  • 不要手动实例化threading.Thread。
  • 不要在ThreadPoolExecutor内部再手动维护一个queue.Queue用于任务调度(除非有特殊需求,通常应依赖Executor的内部队列)。

Triggers

  • 使用 ThreadPoolExecutor 改造 SingleTaskCenter 和 TaskCenter
  • 重构任务中心使用线程池
  • PyQt6 多线程任务管理优化

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.