multiprocessing - 在"Resource temporarily unavailable" 之后,python 多处理池恢复


>>> from multiprocessing import Pool
>>> p = Pool(1000)
Traceback (most recent call last):
 File"<stdin>", line 1, in <module>
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py", line 232, in Pool
 return Pool(processes, initializer, initargs, maxtasksperchild)
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 159, in __init__
 self._repopulate_pool()
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 222, in _repopulate_pool
 w.start()
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 130, in start
 self._popen = Popen(self)
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 121, in __init__
 self.pid = os.fork()
OSError: [Errno 35] Resource temporarily unavailable

>>> p = Pool(1)
Traceback (most recent call last):
 File"<stdin>", line 1, in <module>
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py", line 232, in Pool
 return Pool(processes, initializer, initargs, maxtasksperchild)
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 159, in __init__
 self._repopulate_pool()
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 222, in _repopulate_pool
 w.start()
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 130, in start
 self._popen = Popen(self)
 File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/forking.py", line 121, in __init__
 self.pid = os.fork()
OSError: [Errno 35] Resource temporarily unavailable

有没有什么方法可以避免或补救这个,或者它被认为是一个bug?

时间:

有什么方法可以避免

这样不行。

它是bug?

是的,如果初始值设定失败,则应取消分配所有分配的资源,

无论你试图完成什么任务,都需要在应用程序级别加入对资源使用的限制。

Ticket:http://bugs.python.org/issue19675

...