Skip to content

Commit 673c393

Browse files
authored
bpo-38546: Fix concurrent.futures test_ressources_gced_in_workers() (pythonGH-17652)
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.
1 parent 75bb07e commit 673c393

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lib/test/test_concurrent_futures.py

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

8888

8989
class EventfulGCObj():
90-
def __init__(self, ctx):
91-
mgr = get_context(ctx).Manager()
90+
def __init__(self, mgr):
9291
self.event = mgr.Event()
9392

9493
def __del__(self):
@@ -847,12 +846,21 @@ def test_traceback(self):
847846
def test_ressources_gced_in_workers(self):
848847
# Ensure that argument for a job are correctly gc-ed after the job
849848
# is finished
850-
obj = EventfulGCObj(self.ctx)
849+
mgr = get_context(self.ctx).Manager()
850+
obj = EventfulGCObj(mgr)
851851
future = self.executor.submit(id, obj)
852852
future.result()
853853

854854
self.assertTrue(obj.event.wait(timeout=1))
855855

856+
# explicitly destroy the object to ensure that EventfulGCObj.__del__()
857+
# is called while manager is still running.
858+
obj = None
859+
support.gc_collect()
860+
861+
mgr.shutdown()
862+
mgr.join()
863+
856864

857865
create_executor_tests(ProcessPoolExecutorTest,
858866
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)