Skip to content

Commit b8bbdf0

Browse files
bpo-38546: Fix concurrent.futures test_ressources_gced_in_workers() (GH-17652) (GH-17655)
Fix test_ressources_gced_in_workers() of test_concurrent_futures: explicitly stop the manager to prevent leaking a child process running in the background after the test completes. (cherry picked from commit 673c393) (cherry picked from commit b0eb046) Co-authored-by: Victor Stinner <[email protected]>
1 parent 3dbfe0a commit b8bbdf0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Lib/test/test_concurrent_futures.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def my_method(self):
8484

8585

8686
class EventfulGCObj():
87-
def __init__(self, ctx):
88-
mgr = get_context(ctx).Manager()
87+
def __init__(self, mgr):
8988
self.event = mgr.Event()
9089

9190
def __del__(self):
@@ -818,12 +817,21 @@ def test_traceback(self):
818817
def test_ressources_gced_in_workers(self):
819818
# Ensure that argument for a job are correctly gc-ed after the job
820819
# is finished
821-
obj = EventfulGCObj(self.ctx)
820+
mgr = get_context(self.ctx).Manager()
821+
obj = EventfulGCObj(mgr)
822822
future = self.executor.submit(id, obj)
823823
future.result()
824824

825825
self.assertTrue(obj.event.wait(timeout=1))
826826

827+
# explicitly destroy the object to ensure that EventfulGCObj.__del__()
828+
# is called while manager is still running.
829+
obj = None
830+
test.support.gc_collect()
831+
832+
mgr.shutdown()
833+
mgr.join()
834+
827835

828836
create_executor_tests(ProcessPoolExecutorTest,
829837
executor_mixins=(ProcessPoolForkMixin,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix test_ressources_gced_in_workers() of test_concurrent_futures: explicitly
2+
stop the manager to prevent leaking a child process running in the background
3+
after the test completes.

0 commit comments

Comments
 (0)