Skip to content

[3.11] gh-109295: Clean up multiprocessing in test_asyncio and test_compileall (GH-109298) #109302

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

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from asyncio import events
from asyncio import proactor_events
from asyncio import selector_events
from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
from test.test_asyncio import utils as test_utils
from test import support
from test.support import socket_helper
Expand Down Expand Up @@ -2730,6 +2731,8 @@ def test_get_event_loop_new_process(self):
# multiprocessing.synchronize module cannot be imported.
support.skip_if_broken_multiprocessing_synchronize()

self.addCleanup(multiprocessing_cleanup_tests)

async def main():
pool = concurrent.futures.ProcessPoolExecutor()
result = await self.loop.run_in_executor(
Expand Down
10 changes: 7 additions & 3 deletions Lib/test/test_compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
try:
# compileall relies on ProcessPoolExecutor if ProcessPoolExecutor exists
# and it can function.
from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
from concurrent.futures import ProcessPoolExecutor
from concurrent.futures.process import _check_system_limits
_check_system_limits()
Expand Down Expand Up @@ -54,6 +55,8 @@ class CompileallTestsBase:

def setUp(self):
self.directory = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.directory)

self.source_path = os.path.join(self.directory, '_test.py')
self.bc_path = importlib.util.cache_from_source(self.source_path)
with open(self.source_path, 'w', encoding="utf-8") as file:
Expand All @@ -66,9 +69,6 @@ def setUp(self):
self.source_path3 = os.path.join(self.subdirectory, '_test3.py')
shutil.copyfile(self.source_path, self.source_path3)

def tearDown(self):
shutil.rmtree(self.directory)

def add_bad_source_file(self):
self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
with open(self.bad_source_path, 'w', encoding="utf-8") as file:
Expand Down Expand Up @@ -307,9 +307,13 @@ def _test_ddir_only(self, *, ddir, parallel=True):
script_helper.make_script(path, "__init__", "")
mods.append(script_helper.make_script(path, "mod",
"def fn(): 1/0\nfn()\n"))

if parallel:
self.addCleanup(multiprocessing_cleanup_tests)
compileall.compile_dir(
self.directory, quiet=True, ddir=ddir,
workers=2 if parallel else 1)

self.assertTrue(mods)
for mod in mods:
self.assertTrue(mod.startswith(self.directory), mod)
Expand Down