TL;DR:最も基本的なdispy
サンプル コードを正しく実行することができません。なぜだめですか?
詳細:
私は Python で分散処理を始めようとしていますが、包括的な機能セットがあるため、 dispyライブラリは興味深いと思いました。
しかし、私は彼らの基本的な正規プログラムの例に従おうとしてきましたが、どこにも行き着きません。
- dispy をインストールしました (
python -m pip install dispy
) - 私は同じサブネットアドレスを持つ別のマシンに行き、実行しました
python dispynode.py
. 次の出力が得られるので、うまくいくようです:2016-06-14 10:33:38 dispynode - dispynode バージョン 4.6.14 2016-06-14 10:33:38 asyncoro - epoll
I/O 通知機能を備えたバージョン 4.1
10.0.48.54:51348 で 8 CPU「quit」または「exit」を入力して dispynode を終了し、「stop」を入力して
サービスを停止し、「start」を入力してサービスを再起動し、「cpus」を入力して使用する CPU を変更し、その他を入力
してステータスを取得します。 - クライアント マシンに戻り、 http://dispy.sourceforge.net/_downloads/sample.pyからダウンロードしたサンプル コードを実行します。
# function 'compute' is distributed and executed with arguments
# supplied with 'cluster.submit' below
def compute(n):
import time, socket
time.sleep(n)
host = socket.gethostname()
return (host, n)
if __name__ == '__main__':
# executed on client only; variables created below, including modules imported,
# are not available in job computations
import dispy, random
# distribute 'compute' to nodes; 'compute' does not have any dependencies (needed from client)
cluster = dispy.JobCluster(compute)
# run 'compute' with 20 random numbers on available CPUs
jobs = []
for i in range(20):
job = cluster.submit(random.randint(5,20))
job.id = i # associate an ID to identify jobs (if needed later)
jobs.append(job)
# cluster.wait() # waits until all jobs finish
for job in jobs:
host, n = job() # waits for job to finish and returns results
print('%s executed job %s at %s with %s' % (host, job.id, job.start_time, n))
# other fields of 'job' that may be useful:
# job.stdout, job.stderr, job.exception, job.ip_addr, job.end_time
cluster.print_status() # shows which nodes executed how many jobs etc.
これを実行すると ( python sample.py
)、ハングします。pdb を介してデバッグすると、最終的に でハングしていることがわかりますdispy/__init__.py(117)__call__()
。行は読み取りますself.finish.wait()
。finish は単なる python スレッドであり、wait()
次にlib/python3.5/threading.py(531)wait()
. 待機に達するとハングします。
クライアント マシンで dispynode を実行してみましたが、同じ結果が得られました。クラスターの作成にノードを渡す多くのバリアントを試しました。
cluster = dispy.JobCluster(compute, nodes=['localhost'])
cluster = dispy.JobCluster(compute, nodes=['*'])
cluster = dispy.JobCluster(compute, nodes=[<hostname of the remote node running the client>])
cluster.wait()
行のコメントを外して実行してみましたが、同じ結果が得られました。
ロギング ( cluster = dispy.JobCluster(compute, loglevel = 10)
) を追加すると、クライアント側で次の出力が得られました。
2016-06-14 10:27:01 asyncoro - epoll I/O notifier を使用したバージョン 4.1
2016-06-14 10:27:01 dispy - :51347 の dispy クライアント"_dispy_20160614102701" の障害復旧情報
2016-06-14 10:27:01 dispy - 保留中のジョブ: 0
2016-06-14 10:27:01 dispy - 保留中のジョブ: 1
2016-06-14 10:27:01 dispy - 保留中のジョブ: 2
2016-06-14 10:27:01 dispy - 保留中のジョブ: 3
2016-06-14 10:27:01 dispy - 保留中のジョブ: 4
2016-06-14 10:27:01 dispy - 保留中ジョブ: 5
2016-06-14 10:27:01 dispy - 保留中のジョブ: 6
2016-06-14 10:27:01 dispy - 保留中のジョブ: 7
2016-06-14 10:27:01 dispy - 保留中のジョブ: 8
2016-06-14 10:27:01 dispy - 保留中のジョブ: 9
2016-06-14 10:27:01 dispy - 保留中のジョブ: 10
これは予想外ではないように思えますが、ジョブが実行されていない理由を理解するのには役立ちません。
価値があるのは、_dispy_20160614102701.bak です。
'_cluster', (0, 207)
'compute_1465918021755', (512, 85)
同様に、_dispy_20160614102701.dir:
'_cluster', (0, 207)
'compute_1465918021755', (512, 85)
不安定なバージョンを使用していない限り、私は推測できません。