jobs = []
for i in range(10):
#ジョブを実行し、結果を退避しています。
#※job_server.submitに渡す値
#func=分散して実行するメソッド名
#args=funcで指定したメソッドの引数
#depfuncs=funcで指定したメソッド内で呼び出されるメソッド
#modules=importする必要があるものを指定
jobs.append(job_server.submit(func=sample_function, args=(i,),depfuncs=(get_ip,), modules=("time","socket")))
for job in jobs:
print job()
job_server.print_stats()
実行結果はこんな感じになります。
called sample_function 0
ip address:192.168.1.1
called sample_function 1
ip address:192.168.1.1
called sample_function 2
ip address:192.168.1.1
called sample_function 3
ip address:192.168.1.1
called sample_function 4
ip address:192.168.1.2
called sample_function 5
ip address:192.168.1.2
called sample_function 6
ip address:192.168.1.1
called sample_function 7
ip address:192.168.1.1
called sample_function 8
ip address:192.168.1.2
called sample_function 9
ip address:192.168.1.1
Job execution statistics:
job count | % of all jobs | job time sum | time per job | job server
3 | 30.00 | 3.0282 | 1.009395 | 192.168.1.2:60000
7 | 70.00 | 7.0920 | 1.013143 | local
Time elapsed since server creation 4.65599989891