Title: gh-152356: Fix Windows blocking sampling after target process exit by zainnadeem786 · Pull Request #152471 · python/cpython · GitHub
Open Graph Title: gh-152356: Fix Windows blocking sampling after target process exit by zainnadeem786 · Pull Request #152471 · python/cpython
X Title: gh-152356: Fix Windows blocking sampling after target process exit by zainnadeem786 · Pull Request #152471 · python/cpython
Description: Summary Fixes gh-152356. On Windows, profiling.sampling run --blocking could hang indefinitely after the target process had already exited, leaving an empty binary profile that could not be replayed. The non-blocking sampling path already terminates correctly when the target exits, but the Windows blocking implementation classified the same process-exit condition differently. Root Cause During blocking sampling, the profiler pauses the target through the Windows remote debugging layer. If the target process has already exited, NtSuspendProcess() fails. The Windows implementation currently reports this as a RuntimeError. The sampling loop treats RuntimeError as a recoverable sampling failure and continues retrying, so profiling never finishes and the binary profile writer is never finalized. Other platforms already report terminated processes as ProcessLookupError, which the sampling loop correctly treats as a terminal condition. Changes This patch updates the Windows implementation of _Py_RemoteDebug_StopAllThreads(). When NtSuspendProcess() fails because the target process has already terminated, the remote debugging layer now raises ProcessLookupError instead of RuntimeError. Existing RuntimeError behaviour is preserved for genuine NtSuspendProcess() failures while alive processes are unaffected. No other profiling behaviour changes. Tests Added a Windows-only regression test that: runs profiling.sampling run --binary --mode=cpu --blocking against a short-lived Python script, verifies the command exits successfully, verifies a non-empty binary profile is produced, verifies the generated profile can be replayed successfully. Validation Validated with: PCbuild\build.bat -p x64 -d PCbuild\amd64\python_d.exe -m unittest -v test.test_profiling.test_sampling_profiler.test_blocking.TestBlockingModeCLI PCbuild\amd64\python_d.exe -m test test_profiling PCbuild\amd64\python_d.exe -m test test_importlib test_subprocess manual verification of profiling.sampling run --blocking and profiling.sampling replay git diff --check After this change, Windows blocking sampling terminates correctly once the target process exits and produces a valid replayable binary profile.
Open Graph Description: Summary Fixes gh-152356. On Windows, profiling.sampling run --blocking could hang indefinitely after the target process had already exited, leaving an empty binary profile that could not be replaye...
X Description: Summary Fixes gh-152356. On Windows, profiling.sampling run --blocking could hang indefinitely after the target process had already exited, leaving an empty binary profile that could not be replaye...
Opengraph URL: https://github.com/python/cpython/pull/152471
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f1d1a4e2-84fb-4311-2eaf-72f3e3f47486 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C048:23E48:C8E346:FBC590:6B023B87 |
| html-safe-nonce | fb1f49fcf6aec7c56b7cc2856666971a653d8cc69b41016afc6a17776c4eea20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDQ4OjIzRTQ4OkM4RTM0NjpGQkM1OTA6NkIwMjNCODciLCJ2aXNpdG9yX2lkIjoiNTE3MDEyMDA1NjA1MDQzMjkwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8b4550b4cd377c1d910627f0a3c5858dcce13ad237763c94fde2cd29a300163a |
| hovercard-subject-tag | pull_request:3950265626 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/152471/files |
| twitter:image | https://avatars.githubusercontent.com/u/165761530?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/165761530?s=400&v=4 |
| og:image:alt | Summary Fixes gh-152356. On Windows, profiling.sampling run --blocking could hang indefinitely after the target process had already exited, leaving an empty binary profile that could not be replaye... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width