libgit2 / libgit2/pygit2

repo.walk in thread hangs the main thread

オープン
#1,003 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

support
主要言語
Python
スター
1.7k
フォーク
408
平均マージ
2日 57分
マージ済み PR(30日)
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])

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された Python 再現プログラムから始め、repo.walk、そのイテレータ、および repo.diff の実装について、スレッド処理の動作を調査してください。worker が大規模なリポジトリを処理している間もメインスレッドが応答可能な状態を維持するかを確認し、その後、期待される動作を示すリグレッションテストを追加してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
git, python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。