@@ -54,18 +54,21 @@ def f(x):
5454if __name__ == '__main__':
5555 start_method = sys.argv[1]
5656 set_start_method(start_method)
57- p = Pool(5)
5857 results = []
59- p.map_async(f, [1, 2, 3], callback=results.extend)
60- start_time = time.monotonic()
61- while not results:
62- time.sleep(0.05)
63- # up to 1 min to report the results
64- dt = time.monotonic() - start_time
65- if dt > 60.0:
66- raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt)
58+ with Pool(5) as pool:
59+ pool.map_async(f, [1, 2, 3], callback=results.extend)
60+ start_time = time.monotonic()
61+ while not results:
62+ time.sleep(0.05)
63+ # up to 1 min to report the results
64+ dt = time.monotonic() - start_time
65+ if dt > 60.0:
66+ raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt)
67+
6768 results.sort()
6869 print(start_method, "->", results)
70+
71+ pool.join()
6972"""
7073
7174test_source_main_skipped_in_children = """\
@@ -84,18 +87,21 @@ def f(x):
8487
8588start_method = sys.argv[1]
8689set_start_method(start_method)
87- p = Pool(5)
8890results = []
89- p.map_async(int, [1, 4, 9], callback=results.extend)
90- start_time = time.monotonic()
91- while not results:
92- time.sleep(0.05)
93- # up to 1 min to report the results
94- dt = time.monotonic() - start_time
95- if dt > 60.0:
96- raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt)
91+ with Pool(5) as pool:
92+ pool.map_async(int, [1, 4, 9], callback=results.extend)
93+ start_time = time.monotonic()
94+ while not results:
95+ time.sleep(0.05)
96+ # up to 1 min to report the results
97+ dt = time.monotonic() - start_time
98+ if dt > 60.0:
99+ raise RuntimeError("Timed out waiting for results (%.1f sec)" % dt)
100+
97101results.sort()
98102print(start_method, "->", results)
103+
104+ pool.join()
99105"""
100106
101107# These helpers were copied from test_cmd_line_script & tweaked a bit...
0 commit comments