mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
bpo-29877: compileall: import ProcessPoolExecutor only when needed (GH-4856)
Importing ProcessPoolExecutor may hang or cause an error when the import accesses urandom on a low resource platform https://bugs.python.org/issue29877
This commit is contained in:
parent
9de3632715
commit
1d817e4c82
3 changed files with 17 additions and 11 deletions
|
|
@ -167,7 +167,7 @@ class CompileallTestsBase:
|
|||
self.assertRegex(line, r'Listing ([^WindowsPath|PosixPath].*)')
|
||||
self.assertTrue(os.path.isfile(self.bc_path))
|
||||
|
||||
@mock.patch('compileall.ProcessPoolExecutor')
|
||||
@mock.patch('concurrent.futures.ProcessPoolExecutor')
|
||||
def test_compile_pool_called(self, pool_mock):
|
||||
compileall.compile_dir(self.directory, quiet=True, workers=5)
|
||||
self.assertTrue(pool_mock.called)
|
||||
|
|
@ -177,19 +177,19 @@ class CompileallTestsBase:
|
|||
"workers must be greater or equal to 0"):
|
||||
compileall.compile_dir(self.directory, workers=-1)
|
||||
|
||||
@mock.patch('compileall.ProcessPoolExecutor')
|
||||
@mock.patch('concurrent.futures.ProcessPoolExecutor')
|
||||
def test_compile_workers_cpu_count(self, pool_mock):
|
||||
compileall.compile_dir(self.directory, quiet=True, workers=0)
|
||||
self.assertEqual(pool_mock.call_args[1]['max_workers'], None)
|
||||
|
||||
@mock.patch('compileall.ProcessPoolExecutor')
|
||||
@mock.patch('concurrent.futures.ProcessPoolExecutor')
|
||||
@mock.patch('compileall.compile_file')
|
||||
def test_compile_one_worker(self, compile_file_mock, pool_mock):
|
||||
compileall.compile_dir(self.directory, quiet=True)
|
||||
self.assertFalse(pool_mock.called)
|
||||
self.assertTrue(compile_file_mock.called)
|
||||
|
||||
@mock.patch('compileall.ProcessPoolExecutor', new=None)
|
||||
@mock.patch('concurrent.futures.ProcessPoolExecutor', new=None)
|
||||
@mock.patch('compileall.compile_file')
|
||||
def test_compile_missing_multiprocessing(self, compile_file_mock):
|
||||
compileall.compile_dir(self.directory, quiet=True, workers=5)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue