bpo-35424: emit ResourceWarning at multiprocessing.Pool destruction (GH-10974)

multiprocessing.Pool destructor now emits ResourceWarning
if the pool is still running.
This commit is contained in:
Victor Stinner 2018-12-20 20:33:51 +01:00 committed by GitHub
parent c5d5dfdb22
commit 9a8d1d7562
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 5 deletions

View file

@ -2577,6 +2577,22 @@ class _TestPool(BaseTestCase):
pass
pool.join()
def test_resource_warning(self):
if self.TYPE == 'manager':
self.skipTest("test not applicable to manager")
pool = self.Pool(1)
pool.terminate()
pool.join()
# force state to RUN to emit ResourceWarning in __del__()
pool._state = multiprocessing.pool.RUN
with support.check_warnings(('unclosed running multiprocessing pool',
ResourceWarning)):
pool = None
support.gc_collect()
def raising():
raise KeyError("key")