diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-12-18 22:54:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-18 22:54:33 (GMT) |
commit | 6cdce3ddef805e11d75142f3e20e23c3fe21fdf4 (patch) | |
tree | 35d1df305a3c5a1332b8ab73d14f1b533afe0641 /Lib/test | |
parent | 05c9d31eb62cc45dc3c55a5cdb7cbc713d0421db (diff) | |
download | cpython-6cdce3ddef805e11d75142f3e20e23c3fe21fdf4.zip cpython-6cdce3ddef805e11d75142f3e20e23c3fe21fdf4.tar.gz cpython-6cdce3ddef805e11d75142f3e20e23c3fe21fdf4.tar.bz2 |
bpo-35424: Fix test_multiprocessing_main_handling (GH-11223)
Fix test_multiprocessing_main_handling: use multiprocessing.Pool with
a context manager and then explicitly join the pool.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_multiprocessing_main_handling.py | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/Lib/test/test_multiprocessing_main_handling.py b/Lib/test/test_multiprocessing_main_handling.py index 9fd5c9f..b6abfcc 100644 --- a/Lib/test/test_multiprocessing_main_handling.py +++ b/Lib/test/test_multiprocessing_main_handling.py @@ -54,18 +54,21 @@ if "check_sibling" in __file__: if __name__ == '__main__': start_method = sys.argv[1] set_start_method(start_method) - p = Pool(5) results = [] - p.map_async(f, [1, 2, 3], callback=results.extend) - start_time = time.monotonic() - while not results: - time.sleep(0.05) - # up to 1 min to report the results - dt = time.monotonic() - start_time - if dt > 60.0: - raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt) + with Pool(5) as pool: + pool.map_async(f, [1, 2, 3], callback=results.extend) + start_time = time.monotonic() + while not results: + time.sleep(0.05) + # up to 1 min to report the results + dt = time.monotonic() - start_time + if dt > 60.0: + raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt) + results.sort() print(start_method, "->", results) + + pool.join() """ test_source_main_skipped_in_children = """\ @@ -84,18 +87,21 @@ from multiprocessing import Pool, set_start_method start_method = sys.argv[1] set_start_method(start_method) -p = Pool(5) results = [] -p.map_async(int, [1, 4, 9], callback=results.extend) -start_time = time.monotonic() -while not results: - time.sleep(0.05) - # up to 1 min to report the results - dt = time.monotonic() - start_time - if dt > 60.0: - raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt) +with Pool(5) as pool: + pool.map_async(int, [1, 4, 9], callback=results.extend) + start_time = time.monotonic() + while not results: + time.sleep(0.05) + # up to 1 min to report the results + dt = time.monotonic() - start_time + if dt > 60.0: + raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt) + results.sort() print(start_method, "->", results) + +pool.join() """ # These helpers were copied from test_cmd_line_script & tweaked a bit... |