首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python多处理模块从BioModels数据库下载模型

使用Python多处理模块从BioModels数据库下载模型
EN

Stack Overflow用户
提问于 2016-11-13 06:13:30
回答 1查看 47关注 0票数 0

我正在尝试使用python多处理模块来加速一些计算。第一步是从BioModels数据库中获取大量模型。有一个名为BioServices的接口,可以通过pip install bioservices下载。我已经成功地在串行中做到了这一点,但这需要时间,并将从并行中受益。

代码语言:javascript
复制
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'

目前,这只是初始化bio类并崩溃(或者至少什么都不做)。有人能建议如何修复我的代码吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-11-13 06:48:39

Pool.map的目的是将一个函数应用于可迭代中的所有项,因此您应该这样说:

代码语言:javascript
复制
for i in m:
    ...P.map(f,i)

而不是仅仅

代码语言:javascript
复制
P.map(f, m)

这将为您提供一个字典列表,每个ID对应一个字典。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40568250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档