You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pool dies with excessive workers, but does not cleanup #63874
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2018-11-05.08:37:42.887>created_at=<Date2013-11-21.01:52:19.814>labels= ['3.7', 'library', 'performance']
title='Pool dies with excessive workers, but does not cleanup'updated_at=<Date2018-11-05.08:37:42.886>user='https://github.com/dsoprea'
If you provide a number of processes to a Pool that the OS can't fulfill, Pool will raise an OSError and die, but does not cleanup any of the processes that it has forked.
This is a session in Python where I can allocate a large, but fulfillable, number of processes (just to exhibit what's possible in my current system):
>> from multiprocessing import Pool
>> p = Pool(500)
>> p.close()
>> p.join()
Now, this is a request that will fail. However, even after this fails, I can't allocate even a single worker:
>>> p = Pool(700)
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
The only way to clean this up is to close the parent (the interpreter).
I'm submitting a patch for 2.7.6 that intercepts exceptions and cleans-up the workers before bubbling. The affected method is _repopulate_pool(), and appears to be the same in 2.7.6, 3.3.3, and probably every other recent version of Python.
This is what happens, now: I can go from requesting a number that's too high to immediately requesting one that's also high but within limits, and there's now no problem as all resources have been freed:
>>> from multiprocessing import Pool
>>> p = Pool(700)
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 224, 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(500)
>>> p.close()
>>> p.join()
I'm still hitting this issue in Python 3.6.0 :: Anaconda 4.3.0 (64-bit). Is there a reason this patch has been ignored?
This is on CentOS release 6.5
Winterflower commented on Feb 12, 2017
Winterflowermannequin
Mannequin
More actions
I've reformatted Dustin Oprea's original patch to be compatible with git, applied it to master and executed _test_multiprocessing suite. All tests pass locally.
Winterflower commented on Feb 12, 2017
Winterflowermannequin
Mannequin
More actions
@dsoprea: would you like to open a PR for this issue on Github? if not, are you happy for me to do it?
@Winterflower: Thank you for encouraging @dsoprea to create the new PR and working to convert the previous patch.
@dsoprea: Thank you for taking the time to create the PR especially after this has been sitting unloved for so long.
Though the new workflow using PR's is still in a bit of a state of flux, my understanding is that we will want to have one PR per feature branch (i.e. one for each of 2.7, 3.6, 3.7) that we want to target.
Now that we seem to have spawned two parallel discussion tracks (one here and one in the PR #57), I'm not sure how best to resolve that but for the time being I'll offer code-related comments here as they're much more likely to be preserved (and thus discoverable) for posterity: we do need some sort of tests around this to complete the patch -- something that would exercise both the non-exception and exception paths (and thus would detect that intended call to util.debug()).
I'm trying to figure out how to write the tests. The existing set of tests
for multiprocessing is a near nightmare. It seems like I might have to use
one of the existing "source code" definitions to test for the no-cleanup
(traditional) scenario but then have to define a new one to define the pool
with an initializer that fails. However, then, I'll have to define three
new TestCase-based classes to test for the various start-methods.
For triggering the exception, supplying a Process target that deliberately fails sounds right.
As for tests for the various start methods (fork/forkserver/spawn), if you are looking at the 3.x branches you'll find this was been consolidated so that one test could conceivably be written to handle multiple variants (see Lib/test/_test_multiprocessing.py).
dsoprea commented on Feb 14, 2017
dsopreamannequin
MannequinAuthor
More actions
I don't think this can be tested. Throwing exceptions in the remote process causes exceptions that can't be caught in the same way (when the initializer fails the pool just attempts to recreate the process over and over) and I don't think it'd be acceptable to try to spawn too many processes in order to induce the original problem. There's not a lot of surface area to what we've doing here. We can't simulate failures any other way.
Can I get an agreement on this from someone?
Winterflower commented on Feb 17, 2017
Winterflowermannequin
Mannequin
More actions
Would it be possible to see a review of the existing attempts at testing this issue?
pppery commented on Mar 14, 2017
ppperymannequin
Mannequin
More actions
Can't you just mock the Process class to have a start method that always raises an error?
Activity
dsoprea commentedon Nov 21, 2013
If you provide a number of processes to a Pool that the OS can't fulfill, Pool will raise an OSError and die, but does not cleanup any of the processes that it has forked.
This is a session in Python where I can allocate a large, but fulfillable, number of processes (just to exhibit what's possible in my current system):
Now, this is a request that will fail. However, even after this fails, I can't allocate even a single worker:
The only way to clean this up is to close the parent (the interpreter).
I'm submitting a patch for 2.7.6 that intercepts exceptions and cleans-up the workers before bubbling. The affected method is _repopulate_pool(), and appears to be the same in 2.7.6, 3.3.3, and probably every other recent version of Python.
This is the old version:
This is the new version:
This is what happens, now: I can go from requesting a number that's too high to immediately requesting one that's also high but within limits, and there's now no problem as all resources have been freed:
VladimirFeinberg commentedon Feb 7, 2017
I'm still hitting this issue in Python 3.6.0 :: Anaconda 4.3.0 (64-bit). Is there a reason this patch has been ignored?
This is on CentOS release 6.5
Winterflower commentedon Feb 12, 2017
I've reformatted Dustin Oprea's original patch to be compatible with git, applied it to master and executed _test_multiprocessing suite. All tests pass locally.
Winterflower commentedon Feb 12, 2017
@dsoprea: would you like to open a PR for this issue on Github? if not, are you happy for me to do it?
dsoprea commentedon Feb 12, 2017
#57
On Sun, Feb 12, 2017 at 5:29 PM, Camilla Montonen <report@bugs.python.org>
wrote:
applio commentedon Feb 13, 2017
@Winterflower: Thank you for encouraging @dsoprea to create the new PR and working to convert the previous patch.
@dsoprea: Thank you for taking the time to create the PR especially after this has been sitting unloved for so long.
Though the new workflow using PR's is still in a bit of a state of flux, my understanding is that we will want to have one PR per feature branch (i.e. one for each of 2.7, 3.6, 3.7) that we want to target.
Now that we seem to have spawned two parallel discussion tracks (one here and one in the PR #57), I'm not sure how best to resolve that but for the time being I'll offer code-related comments here as they're much more likely to be preserved (and thus discoverable) for posterity: we do need some sort of tests around this to complete the patch -- something that would exercise both the non-exception and exception paths (and thus would detect that intended call to util.debug()).
dsoprea commentedon Feb 13, 2017
Okay. Thanks for weighing-in.
I'm trying to figure out how to write the tests. The existing set of tests
for multiprocessing is a near nightmare. It seems like I might have to use
one of the existing "source code" definitions to test for the no-cleanup
(traditional) scenario but then have to define a new one to define the pool
with an initializer that fails. However, then, I'll have to define three
new TestCase-based classes to test for the various start-methods.
Any suggestions?
On Mon, Feb 13, 2017 at 11:50 AM, Davin Potts <report@bugs.python.org>
wrote:
applio commentedon Feb 13, 2017
For triggering the exception, supplying a Process target that deliberately fails sounds right.
As for tests for the various start methods (fork/forkserver/spawn), if you are looking at the 3.x branches you'll find this was been consolidated so that one test could conceivably be written to handle multiple variants (see Lib/test/_test_multiprocessing.py).
dsoprea commentedon Feb 14, 2017
I don't think this can be tested. Throwing exceptions in the remote process causes exceptions that can't be caught in the same way (when the initializer fails the pool just attempts to recreate the process over and over) and I don't think it'd be acceptable to try to spawn too many processes in order to induce the original problem. There's not a lot of surface area to what we've doing here. We can't simulate failures any other way.
Can I get an agreement on this from someone?
Winterflower commentedon Feb 17, 2017
Would it be possible to see a review of the existing attempts at testing this issue?
pppery commentedon Mar 14, 2017
Can't you just mock the Process class to have a start method that always raises an error?
JulienPalard commentedon Nov 4, 2018
New changeset 5d236ca by Julien Palard in branch 'master':
bpo-19675: Terminate processes if construction of a pool is failing. (GH-5614)
5d236ca