|
22 | 22 | from profiling.sampling.gecko_collector import GeckoCollector |
23 | 23 |
|
24 | 24 | from test.support.os_helper import unlink |
25 | | -from test.support import force_not_colorized_test_class, SHORT_TIMEOUT |
| 25 | +from test.support import ( |
| 26 | + force_not_colorized_test_class, |
| 27 | + SHORT_TIMEOUT, |
| 28 | + script_helper, |
| 29 | + os_helper, |
| 30 | + SuppressCrashReport, |
| 31 | +) |
26 | 32 | from test.support.socket_helper import find_unused_port |
27 | 33 | from test.support import requires_subprocess, is_emscripten |
28 | 34 | from test.support import captured_stdout, captured_stderr |
@@ -3011,33 +3017,24 @@ def worker(x): |
3011 | 3017 | results = list(executor.map(worker, [1, 2, 3])) |
3012 | 3018 | print(f"Results: {results}") |
3013 | 3019 | ''' |
3014 | | - with tempfile.NamedTemporaryFile( |
3015 | | - mode='w', suffix='.py', delete=False |
3016 | | - ) as script_file: |
3017 | | - script_file.write(test_script) |
3018 | | - script_file.flush() |
3019 | | - script_name = script_file.name |
3020 | | - |
3021 | | - self.addCleanup(os.unlink, script_name) |
3022 | | - |
3023 | | - result = subprocess.run( |
3024 | | - [ |
3025 | | - sys.executable, |
3026 | | - "-m", "profiling.sampling.sample", |
3027 | | - "-d", "1", |
3028 | | - "-i", "100000", |
3029 | | - script_name, |
3030 | | - ], |
3031 | | - capture_output=True, |
3032 | | - text=True, |
3033 | | - timeout=10 |
3034 | | - ) |
| 3020 | + # Use test helpers to spawn a real Python subprocess so that |
| 3021 | + # PermissionError (if any) is emitted by the child on stderr and |
| 3022 | + # can be handled consistently with other tests. |
| 3023 | + with os_helper.temp_dir() as temp_dir: |
| 3024 | + script = script_helper.make_script( |
| 3025 | + temp_dir, 'test_process_pool_executor_pickle', test_script |
| 3026 | + ) |
| 3027 | + with SuppressCrashReport(): |
| 3028 | + with script_helper.spawn_python(script, stderr=subprocess.PIPE) as proc: |
| 3029 | + proc.wait() |
| 3030 | + stdout = proc.stdout.read() |
| 3031 | + stderr = proc.stderr.read() |
3035 | 3032 |
|
3036 | | - if "PermissionError" in result.stderr: |
| 3033 | + if b"PermissionError" in stderr: |
3037 | 3034 | self.skipTest("Insufficient permissions for remote profiling") |
3038 | 3035 |
|
3039 | | - self.assertIn("Results: [2, 4, 6]", result.stdout) |
3040 | | - self.assertNotIn("Can't pickle", result.stderr) |
| 3036 | + self.assertIn(b"Results: [2, 4, 6]", stdout) |
| 3037 | + self.assertNotIn(b"Can't pickle", stderr) |
3041 | 3038 |
|
3042 | 3039 |
|
3043 | 3040 | if __name__ == "__main__": |
|
0 commit comments