代码运行平稳了一段时间,然后突然它给出 OSError:[Errno 12]无法分配内存
def initialize(site):
global pool
if site == 'OT':
for jobId in JobIdsOT:
argumentList = [jobId, site]
pool.map(assignTask, [argumentList])
elif site == 'LI':
for jobId in JobIdsLI:
argumentList = [jobId, site]
pool.map(assignTask, [argumentList])
堆栈跟踪:
Traceback (most recent call last):
File "LogDumper.py", line 301, in <module>
main()
File "LogDumper.py", line 58, in main
initialize('OT')
File "LogDumper.py", line 78, in initialize
pool.map(assignTask, [argumentList])
File "/usr/lib64/python2.6/multiprocessing/pool.py", line 148, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib64/python2.6/multiprocessing/pool.py", line 422, in get
raise self._value
OSError: [Errno 12] Cannot allocate memory
我提到了这个问题Python cannot allocate memory using multiprocessing.pool。但我不确定解决方案。
如何解决上述问题?
答案 0 :(得分:0)
更改为。
for jobId in JobIdsOT:
argumentList.append( (jobId, site) )
pool.map(assignTask, argumentList)
pool.map(...
只需要一个iterable
,并且只能为所有工作调用一次。