大きな ctype 配列をセグメント化し、それらを並行して処理しています。以下のエラーが表示されましたが、配列のあるセグメントが別のセグメントより先に処理を終了しているためだと思います。process.join() を使用してプロセスの最初のセットを待機させようとしましたが、うまくいきません。アイデア?
Exception RuntimeError: RuntimeError('cannot join current thread',) in <Finalize object, dead> ignored
使用:
....
with closing(multiprocessing.Pool(initializer=init(array))) as p:
del array #Since the array is now stored in a shared array destroy the array ref for memory reasons
step = y // cores
if step != 0:
jobs =[]
for i in range (0, y, step):
process = p.Process(target=stretch, args= (shared_arr,slice(i, i+step)),kwargs=options)
jobs.append(process)
process.start()
for j in jobs:
j.join()
del jobs
del process
アップデート:
#Create an ctypes array
array = ArrayConvert.SharedMemArray(array)
#Create a global of options
init_options(options) #options is a dict
with closing(multiprocessing.Pool(initializer=init(array))) as p:
del array #Since the array is not stored in a shared array destroy the array ref for memory reasons
step = y // cores
if step != 0:
for i in range (0, y, step):
#Package all the options into a global dictionary
p.map_async(stretch,[slice(i, i+step)])
#p.apply_async(stretch,args=(shared_arr,slice(i, i+step)),kwargs=options)
p.join()
def init_options(options_):
global kwoptions
kwoptions = options_
map_async に渡す関数は別のモジュールに格納されているため、その関数にグローバル kwoptions を渡すのに苦労しています。このようにモジュール間でグローバルを渡すのは正しくないようです (unpythonic)。これは、map_async を介して kwargs を渡すことができる方法ですか。
別のもの (適用またはプロセス) を使用してマルチプロセッシングを作り直す必要がありますか?