bpo-35477: multiprocessing.Pool.__enter__() fails if called twice (GH-11134)

multiprocessing.Pool.__enter__() now fails if the pool is not
running: "with pool:" fails if used more than once.
This commit is contained in:
Victor Stinner 2018-12-13 02:15:30 +01:00 committed by GitHub
parent 502fe19b10
commit 08c2ba0717
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 8 deletions

View file

@ -2561,6 +2561,22 @@ class _TestPool(BaseTestCase):
# they were released too.
self.assertEqual(CountedObject.n_instances, 0)
def test_enter(self):
if self.TYPE == 'manager':
self.skipTest("test not applicable to manager")
pool = self.Pool(1)
with pool:
pass
# call pool.terminate()
# pool is no longer running
with self.assertRaises(ValueError):
# bpo-35477: pool.__enter__() fails if the pool is not running
with pool:
pass
pool.join()
def raising():
raise KeyError("key")