-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-140729: Add __mp_main__ as a duplicate for __main__ for pickle to work #140735
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
0c858f9
4cc0482
08de5c3
e9bd308
285a66f
c4b5152
9c6c76b
8b93ec3
c2e66dd
59c1c1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,13 @@ | |
| from profiling.sampling.gecko_collector import GeckoCollector | ||
|
|
||
| from test.support.os_helper import unlink | ||
| from test.support import force_not_colorized_test_class, SHORT_TIMEOUT | ||
| from test.support import ( | ||
| force_not_colorized_test_class, | ||
| SHORT_TIMEOUT, | ||
| script_helper, | ||
| os_helper, | ||
| SuppressCrashReport, | ||
| ) | ||
| from test.support.socket_helper import find_unused_port | ||
| from test.support import requires_subprocess, is_emscripten | ||
| from test.support import captured_stdout, captured_stderr | ||
|
|
@@ -3007,5 +3013,49 @@ def test_parse_mode_function(self): | |
| profiling.sampling.sample._parse_mode("invalid") | ||
|
|
||
|
|
||
| @requires_subprocess() | ||
| @skip_if_not_supported | ||
| class TestProcessPoolExecutorSupport(unittest.TestCase): | ||
| """ | ||
| Test that ProcessPoolExecutor works correctly with profiling.sampling. | ||
| """ | ||
|
|
||
| def test_process_pool_executor_pickle(self): | ||
| # gh-140729: test use ProcessPoolExecutor.map() can sampling | ||
| test_script = ''' | ||
| import concurrent.futures | ||
|
|
||
| def worker(x): | ||
| return x * 2 | ||
|
|
||
| if __name__ == "__main__": | ||
| with concurrent.futures.ProcessPoolExecutor() as executor: | ||
| results = list(executor.map(worker, [1, 2, 3])) | ||
| print(f"Results: {results}") | ||
| ''' | ||
| with os_helper.temp_dir() as temp_dir: | ||
| script = script_helper.make_script( | ||
| temp_dir, 'test_process_pool_executor_pickle', test_script | ||
| ) | ||
| with SuppressCrashReport(): | ||
| with script_helper.spawn_python( | ||
| "-m", "profiling.sampling.sample", | ||
| "-d", "1", | ||
|
||
| "-i", "100000", | ||
| script, | ||
| stderr=subprocess.PIPE, | ||
| text=True | ||
| ) as proc: | ||
| proc.wait(timeout=10) | ||
|
||
| stdout = proc.stdout.read() | ||
| stderr = proc.stderr.read() | ||
|
|
||
| if "PermissionError" in stderr: | ||
| self.skipTest("Insufficient permissions for remote profiling") | ||
|
|
||
| self.assertIn("Results: [2, 4, 6]", stdout) | ||
| self.assertNotIn("Can't pickle", stderr) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix pickling error in the sampling profiler when using ``concurrent.futures.ProcessPoolExecutor`` | ||
| script can not be properly pickled and executed in worker processes. |
Uh oh!
There was an error while loading. Please reload this page.