Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.7] bpo-38546: Backport multiprocessing tests fixes from master #19689

Merged
merged 4 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-38546: multiprocessing tests stop the resource tracker (GH-17641) (
…GH-17647)

Multiprocessing and concurrent.futures tests now stop the resource
tracker process when tests complete.

Add ResourceTracker._stop() method to
multiprocessing.resource_tracker.

Add _cleanup_tests() helper function to multiprocessing.util: share
code between multiprocessing and concurrent.futures tests.

(cherry picked from commit 9707e8e)
(cherry picked from commit 35acb35)
  • Loading branch information
vstinner committed Apr 23, 2020
commit 53adc98a174829b5b8a58d4d0c96583b1d547a4f
21 changes: 21 additions & 0 deletions Lib/multiprocessing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,24 @@ def spawnv_passfds(path, args, passfds):
finally:
os.close(errpipe_read)
os.close(errpipe_write)


def _cleanup_tests():
"""Cleanup multiprocessing resources when multiprocessing tests
completed."""

from test import support

# cleanup multiprocessing
process._cleanup()

# Stop the ForkServer process if it's running
from multiprocessing import forkserver
forkserver._forkserver._stop()

# bpo-37421: Explicitly call _run_finalizers() to remove immediately
# temporary directories created by multiprocessing.util.get_temp_dir().
_run_finalizers()
support.gc_collect()

support.reap_children()
12 changes: 1 addition & 11 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5050,17 +5050,7 @@ def tearDownModule():
if need_sleep:
time.sleep(0.5)

multiprocessing.process._cleanup()

# Stop the ForkServer process if it's running
from multiprocessing import forkserver
forkserver._forkserver._stop()

# bpo-37421: Explicitly call _run_finalizers() to remove immediately
# temporary directories created by multiprocessing.util.get_temp_dir().
multiprocessing.util._run_finalizers()

test.support.gc_collect()
multiprocessing.util._cleanup_tests()

remote_globs['setUpModule'] = setUpModule
remote_globs['tearDownModule'] = tearDownModule
2 changes: 2 additions & 0 deletions Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
BrokenExecutor)
from concurrent.futures.process import BrokenProcessPool
from multiprocessing import get_context
import multiprocessing.util


def create_future(state=PENDING, exception=None, result=None):
Expand Down Expand Up @@ -1253,6 +1254,7 @@ def test_main():
test.support.run_unittest(__name__)
finally:
test.support.reap_children()
multiprocessing.util._cleanup_tests()

if __name__ == "__main__":
test_main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Multiprocessing and concurrent.futures tests now stop the resource tracker
process when tests complete.