2016-11-12 9 views
0

私はいくつかの計算を高速化するために、Pythonマルチプロセッシングモジュールを使用しようとしています。最初のステップは、BioModelsデータベースから多数のモデルを取得することです。これには、pip install bioservicesでダウンロードできるBioServicesというAPIがあります。私はこれをシリアルでやり遂げましたが、これには時間がかかり、並列化の恩恵を受けるでしょう。Pythonマルチプロセッシングモジュールを使用してBioModelsデータベースからモデルをダウンロードする

bio=bioservices.BioModels() #initialize the class for downloading models 
m=bio.getAllCuratedModelsId() #assign model ID's to the m (a python list) 
def f(ID): 
    dct={} 
    name=bio.getModelNameById(ID)#retrieve the model name for the result dict key 
    print 'running {}'.format(name) #print some information so you can see the program working 
    dct[name]=bio.getModelSBMLById(ID) #get the model and assign as value in dct 
    time.sleep(0.5) #stop the program for a bit to prevent bombarding the services and being cut out 
    return dct 
model_dct={} 
P=multiprocessing.Pool(8) 
for i in m: 
    model_dct.update(P.map(f,i)) # parallelize 

print time.time()-start+'seconds' 

現在のところ、これはバイオクラスを初期化しており、少なくともクラッシュする(または少なくとも何もしない)ことです。誰も私のコードを修正する方法を提案できますか?

おかげ

答えて

0

Pool.mapは反復可能で、すべてのアイテムに関数を適用するためのものですので、あなたが言う必要があります。

for i in m: 
    ...P.map(f,i) 

ではなく、単に

P.map(f, m) 

をこれはあなたを与えるだろう各IDごとに1つずつ、dictsのリスト。

関連する問題