Python多处理:增加池大小后出现断开管道异常
问题描述
我得到的异常。我所做的只是增加了泳池数量
代码
def parse(url):
r = request.get(url)
POOL_COUNT = 75
with Pool(POOL_COUNT) as p:
result = p.map(parse, links)
File "/usr/lib64/python3.5/multiprocessing/pool.py", line 130, in worker
put((job, i, (False, wrapped)))
File "/usr/lib64/python3.5/multiprocessing/queues.py", line 355, in put
self._writer.send_bytes(obj)
File "/usr/lib64/python3.5/multiprocessing/connection.py", line 200, in send_bytes
self._send_bytes(m[offset:offset + size])
File "/usr/lib64/python3.5/multiprocessing/connection.py", line 404, in _send_bytes
self._send(header + buf)
File "/usr/lib64/python3.5/multiprocessing/connection.py", line 368, in _send
n = write(self._handle, buf)
BrokenPipeError: [Errno 32] Broken pipe
Process ForkPoolWorker-26:
Traceback (most recent call last):
File "/usr/lib64/python3.5/multiprocessing/pool.py", line 125, in worker
put((job, i, result))
File "/usr/lib64/python3.5/multiprocessing/queues.py", line 355, in put
self._writer.send_bytes(obj)
File "/usr/lib64/python3.5/multiprocessing/connection.py", line 200, in send_bytes
self._send_bytes(m[offset:offset + size])
File "/usr/lib64/python3.5/multiprocessing/connection.py", line 404, in _send_bytes
self._send(header + buf)
File "/usr/lib64/python3.5/multiprocessing/connection.py", line 368, in _send
n = write(self._handle, buf)
BrokenPipeError: [Errno 32] Broken pipe
解决方案
我也看到了管道损坏异常。但我的要复杂得多。
单独增加池大小会导致异常的一个原因是,您在请求模块中获取了太多内容,因此可能会导致内存不足。然后它会出现故障,特别是你有一个小掉期。编辑1:我认为这是由内存使用引起的。太多的池连接占用了太多的内存,最终导致内存中断。它很难调试,我自己将池大小限制为4,因为我有一个小的RAM和大的包。
相关文章