这只是带有 parallel-python 标签的第二个问题。在查看了文档并在谷歌上搜索了该主题后,我来到了这里,因为这是我获得最佳答案和建议的地方。
以下是向pp提交所有相关信息的API(我认为它被称为)。
def submit(self, func, args=(), depfuncs=(), modules=(),
callback=None, callbackargs=(), group='default', globals=None):
"""Submits function to the execution queue
func - function to be executed
args - tuple with arguments of the 'func'
depfuncs - tuple with functions which might be called from 'func'
modules - tuple with module names to import
callback - callback function which will be called with argument
list equal to callbackargs+(result,)
as soon as calculation is done
callbackargs - additional arguments for callback function
group - job group, is used when wait(group) is called to wait for
jobs in a given group to finish
globals - dictionary from which all modules, functions and classes
will be imported, for instance: globals=globals()
"""
这是我的提交声明及其参数:
job_server.submit(reify, (pop1, pop2, 1000),
depfuncs = (key_seq, Chromosome, Params, Node, Tree),
modules = ("math",),
callback = sum.add, globals = globals())
中所有大写depfuncs
的名称都是类的名称。我不确定将课程放在哪里,或者即使我需要将它们包含在globals()
字典中。但是当我用depfuncs()
空运行它时,它会引发诸如“ Tree not defined
”之类的错误(例如)。
现在,key_seq
是一个生成器,所以我必须使用它的一个实例才能使用.next()
:
def key_seq():
a = 0
while True:
yield a
a = a + 1
ks = key_seq()
ks
中定义globals()
。当我没有在其他任何地方包含它时,我收到一个错误说' ks is not defined
'。当我包含ks
in 时depfuncs
,这是错误:
Traceback (most recent call last):
File "C:\Python26\Code\gppp.py", line 459, in <module>
job_server.submit(reify, (pop1, pop2, 1000), depfuncs = (key_seq, ks, Chromosome, Params, Node, Tree), modules = ("math",), callback = sum.add, globals = globals())
File "C:\Python26\lib\site-packages\pp.py", line 449, in submit
sfunc = self.__dumpsfunc((func, ) + depfuncs, modules)
File "C:\Python26\lib\site-packages\pp.py", line 634, in __dumpsfunc
sources = [self.__get_source(func) for func in funcs]
File "C:\Python26\lib\site-packages\pp.py", line 713, in __get_source
sourcelines = inspect.getsourcelines(func)[0]
File "C:\Python26\lib\inspect.py", line 678, in getsourcelines
lines, lnum = findsource(object)
File "C:\Python26\lib\inspect.py", line 519, in findsource
file = getsourcefile(object) or getfile(object)
File "C:\Python26\lib\inspect.py", line 441, in getsourcefile
filename = getfile(object)
File "C:\Python26\lib\inspect.py", line 418, in getfile
raise TypeError('arg is not a module, class, method, '
TypeError: arg is not a module, class, method, function, traceback, frame, or code object
我很确定arg
指的是ks
. 那么,我该在哪里.submit()
讲述ks
呢?我不明白应该去哪里。谢谢。