repo.walk in thread hangs the main thread
未关闭
还没有人认领这个 Issue。
support
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 408
- 平均合并
- 2 天 57 分钟
- 30 天内合并 PR
- 7
描述
When calling repo.walk in a new thread, it blocks the main thread until it finished!!!
See the example code below, when run with a huge repo (qt5, chromium e.g.), the main thread won't print any message until the repo.walk ended. (Use iter also the same)
It seems that repo.diff also have the problem.
from pygit2 import Repository, GIT_SORT_TOPOLOGICAL
from threading import Thread
import sys
import time
def thread_func(repo_dir):
repo = Repository(repo_dir)
print(">>>>>>>> begin diff")
commits = list(repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL))
#for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
# continue
print(">>>>>>>> end diff")
def test(repo_dir):
t = Thread(target=thread_func, args=[repo_dir])
t.start()
while t.is_alive():
print("main thread...")
time.sleep(0.01)
if __name__ == "__main__":
if len(sys.argv) != 2:
print(">>>>>>>> Invalid argument")
sys.exit(-1)
test(sys.argv[1])
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从提供的 Python 复现程序开始,检查 repo.walk、其迭代器和 repo.diff 的实现,了解线程行为。验证 worker 处理大型 repository 时主线程是否仍能保持响应,然后添加能够展示预期行为的回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- git, python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100