0

私は、リポジトリを通過し、ディレクトリとファイルを一覧表示する一種の「クローラー」に取り組んできました。遭遇するすべてのディレクトリに対して、そのディレクトリなどに対して同じことを再帰的に行うスレッドを作成します。事実上、これにより、リポジトリで検出されたすべてのディレクトリに対して非常に短命のスレッドが作成されます。(たった 1 つのパスで情報を要求するのにそれほど時間はかかりません。数万のパスがあります)。

ロジックは次のようになります。

import threading
import perforce as Perforce #custom perforce class
from pathlib import Path

p4 = Perforce()
p4.connect()

class Dir():
    def __init__(self, path):
        self.dirs = []
        self.files = []
        self.path = path

        self.crawlers = []

    def build_crawler(self):
        worker = Crawler(self)
        # append to class variable to keep it from being deleted
        self.crawlers.append(worker)
        worker.start()

class Crawler(threading.Thread):
    def __init__(self, dir):
        threading.Thread.__init__(self)
        self.dir = dir

    def run(self):
        depotdirs = p4.getdepotdirs(self.dir.path)
        depotfiles = p4.getdepotfiles(self.dir.path)

        for p in depotdirs:
            if Path(p).is_dir():
                _d = Dir(self.dir, p)
                self.dir.dirs.append(_d)

        for p in depotfiles:
            if Path(p).is_file():
                f = File(p) # File is like Dir, but with less stuff, just a path.
                self.dir.files.append(f)

        for dir in self.dir.dirs:
            dir.build_crawler()
            for worker in d.crawlers:
                worker.join()

明らかにこれは完全なコードではありませんが、私がやっていることを表しています。

私の質問は__init__、クローラー クラスのメソッドでこの Perforce クラスのインスタンスを作成して、リクエストを個別に実行できるかどうかです。現在、join()作成されたスレッドを呼び出して、完了を待機し、同時 perforce 呼び出しを回避する必要があります。

試してみましたが、作成できる接続の数には制限があるようです: 確かな数はありませんが、どこかで Perforce が接続を拒否し始めました。同時リクエストの数に。

本当に私が求めているのは2つあると思います.数万のファイルを持つリポジトリを表すデータモデルを作成するより良い方法はありますか? 、もしそうなら、どのように。

どんな助けでも大歓迎です:)

4

1 に答える 1