入力を受け取り処理するいくつかのプロセスを設定したいので、この結果の結果を処理したい別のタスクにします。本質的に、各タスクは(同じタイプの)ゼロまたは複数の新しいタスクをもたらし、最終的にすべてのタスクは新しいタスクを生成しない。すべてのプロセスがキューから取得しようとしていてキューが空の場合の処理を終了しますか?
私はキューがこれに適していると思ったので、入力キューと結果キューを追加して、何も新しい結果にならないタスクを追加しました。いつでもキューは空でもかまいませんが、別のプロセスがタスクを処理している場合は、キューを追加できます。
したがって、私はすべてのプロセスが同時に入力キューから取得しようとしているときに終了します。
私は、一般に、Pythonのマルチプロセッシングとマルチプロセッシングの両方に全く新しいものです。
class Consumer(Process):
def __init__(self, name):
super().__init__(name=name)
def run():
# This is where I would have the task try to get a new task off of the
# queue and then calculate the results and put them into the queue
# After which it would then try to get a new task and repeat
# If this an all other processes are trying to get and the queue is
# empty That is the only time I know that everything is complete and can
# continue
pass
def start_processing():
in_queue = Queue()
results_queue = Queue()
consumers = [Consumer(str(i)) for i in range(cpu_count())]
for i in consumers:
i.start()
# Wait for the above mentioned conditions to be true before continuing
この時点で、これは私が前方に移動する前に作業する必要があるもののように思えるので、私は唯一の絶対的なスケルトンコードを持っています。基本的に私はプロセスとキューを作成しました。 –
概要コードをいくつか追加しました –