0
我注意到这种行为在python池分配。即使我在池中有20个进程,但是当我为8个进程执行map_async时,我不会执行所有进程,而只会执行4个进程。当那4个完成时,它再发送两个,然后当这两个完成时发送一个。多处理 - 池分配
当我抛出20多个数据时,它会全部运行20次,直到队列中开始少于20个时,重复上述行为。
我认为这是有意完成的,但看起来很奇怪。我的目标是尽快处理请求,显然这种行为不适合。
使用Python 2.6 billiard为maxtasksperchild支持
任何想法我怎么能提高呢?
代码:
mypool = pool.Pool(processes=settings['num-processes'], initializer=StartChild, maxtasksperchild=10)
while True:
lines = DbData.GetAll()
if len(lines) > 0:
print 'Starting to process: ', len(lines), ' urls'
Res = mypool.map_async(RunChild, lines)
Returns = Res.get(None)
print 'Pool returns: ', idx, Returns
else:
time.sleep(0.5)
谢谢,这有助于改进我的脚本。我摆脱了默认池处理,并根据您的示例实施了我自己的处理。 – SorinV 2012-04-30 03:29:16