これは、parallel-python タグを使用した 2 番目の質問にすぎません。ドキュメントに目を通し、主題をグーグルで検索した後、回答と提案で最高の幸運が得られた場所であるため、ここに来ました。
以下は、すべての関連情報を pp.
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
と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
ますか?何がどこにあるのかわかりません。ありがとう。