私は質問に固執しており、私は良い答えを見つけることができません。マルチプロセッシングがなぜ空のキューの後で初期化されないのですか?
私は、フォルダからイメージを取得し、プールに名前を付けたキューに入れるスクリプトを持っています。 で真の場合ループiはフォルダに画像があるかどうかを確認します。はい、私はこのイメージを取って、このプールのキューに入れて、私はこれらの画像に顔を持っているかどうかを確認する機能を実行するプロセスを作成し、他の無関係なものを行います。
私の質問は、コードから珍しいcomportamentに来る。フォルダ内にイメージがある場合は、プロセスの各プロセスに対してイメージが1つずつ配布されます。プロセスよりも画像が少ない場合、またはフォルダが空の場合は、新しい画像をフォルダに入れるとプロセスが作成されません。
これにはどのような説明がありますか?
は、ここでは、コードの関連部分です:
def face_search(pool, qtd_pool):
# Do face recognition and move files
# When files moved, the folder with images get empty until i put new images
# if there's no face, the image is deleted from disk
# At the end, it return True and enter in the next image loop
if __name__ == '__main__':
#irrelevant stuff
while true:
pool_get = os.listdir(/some_directory/)
qtd_pool = len(pool_get)
pool = Queue()
for image in pool_get:
pool.put('/some_directory/'+image)
# down below i create the Process, and join then when finished. They would be created for every loop, right? Why they don't act like that?
procs = [Process(target = face_search, args=(pool, qtd_pool,)) for i in xrange(nthreads)]
for p in procs: p.start()
for p in procs: p.join()
編集。イメージは新しいイメージが利用可能になるまで待機するか、イメージが処理された後に終了しますか? – stovfl
画像処理後に終了します。真のループが次の画像と同じ処理をするよりも、 –