没有打印的 Python 多处理开始和停止?



当我启动或停止进程时,标准输出中有一行,如<Process(Process-1, started)>。但是我不想打印出这一行,我该如何防止这种情况?

我的代码:

import multiprocessing as mp
def spawn(f):
def func(pipe, param):
pipe.send(f(param))
pipe.close()
return func

def parallel_map(func, params, num_of_processes=None):
num_of_processes = mp.cpu_count() if not num_of_processes else num_of_processes
pipes = [mp.Pipe() for i in range(num_of_processes)]
result = []
for step in xrange(0, len(params), num_of_processes):
tmp_nop = num_of_processes if step + num_of_processes <= len(params) else len(params) - step
processes = [mp.Process(target=spawn(func), args=(pipes[i][1], params[step + i]))
for i in range(tmp_nop)]
for process in processes:
process.start()
for process in processes:
print process
process.join()
result = result + [p.recv() for (p, c) in pipes[:tmp_nop]]
return result

出于某种原因,您在代码中包含了一行print process,该行准确地打印出您希望它不打印的内容。删除该行,一切都应该很好。

相关内容

  • 没有找到相关文章

最新更新