Skip to content

Commit b0eb046

Browse files
authored
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)
1 parent 35acb35 commit b0eb046

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
@@ -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):
@@ -848,12 +847,21 @@ def test_traceback(self):
848847
def test_ressources_gced_in_workers(self):
849848
# Ensure that argument for a job are correctly gc-ed after the job
850849
# is finished
851-
obj = EventfulGCObj(self.ctx)
850+
mgr = get_context(self.ctx).Manager()
851+
obj = EventfulGCObj(mgr)
852852
future = self.executor.submit(id, obj)
853853
future.result()
854854

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

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

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