Commit 1b77e70c authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[SuperSize] Ensure BulkForkAndCall() cleans up |pool| on exception.

For BulkForkAndCall(), the first exception encountered can get
re-raised. However, this bypasses code to clean |pool|. For the
upcoming work to convert SuperSize to Python 3, this causes

  parallel_test.py: testBulkForkAndCall_exception()

to hang, if another test is also run, and vpython3 (instead of python3)
is used.

This CL prevents the problem by ensuring that BulkForkAndCall() cleans
up |pool| when an exception is raised.

Also fix missing parameter to _ForkTestHelper() in
testBulkForkAndCall_exception().

Bug: 1054018
Change-Id: I2942438130700fa7ccf804064ae317159c2aa895
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107121Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751228}
parent 2d2e1377
...@@ -209,12 +209,14 @@ def BulkForkAndCall(func, arg_tuples, **kwargs): ...@@ -209,12 +209,14 @@ def BulkForkAndCall(func, arg_tuples, **kwargs):
pool = _MakeProcessPool(arg_tuples, **kwargs) pool = _MakeProcessPool(arg_tuples, **kwargs)
wrapped_func = _FuncWrapper(func) wrapped_func = _FuncWrapper(func)
for result in pool.imap_unordered(wrapped_func, xrange(len(arg_tuples))): try:
_CheckForException(result) for result in pool.imap_unordered(wrapped_func, xrange(len(arg_tuples))):
yield result _CheckForException(result)
pool.close() yield result
pool.join() finally:
_all_pools.remove(pool) pool.close()
pool.join()
_all_pools.remove(pool)
def CallOnThread(func, *args, **kwargs): def CallOnThread(func, *args, **kwargs):
......
...@@ -149,7 +149,7 @@ class ConcurrentTest(unittest.TestCase): ...@@ -149,7 +149,7 @@ class ConcurrentTest(unittest.TestCase):
def testBulkForkAndCall_exception(self): def testBulkForkAndCall_exception(self):
parent_pid = os.getpid() parent_pid = os.getpid()
results = parallel.BulkForkAndCall(_ForkTestHelper, results = parallel.BulkForkAndCall(_ForkTestHelper,
[(1, 'a', self, parent_pid)]) [(1, 'a', None, self, parent_pid)])
self.assertRaises(TypeError, results.next) self.assertRaises(TypeError, results.next)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment