Add Runner.is_worker() helper method#222
Open
amritamishra01 wants to merge 2 commits intopsf:mainfrom
Open
Conversation
7dc8ff4 to
ab0a4c3
Compare
vstinner
reviewed
Nov 24, 2025
Member
vstinner
left a comment
There was a problem hiding this comment.
Please revert unrelated changes.
doc/api.rst
Outdated
|
|
||
| .. module:: pyperf | ||
|
|
||
| The module version... |
Member
There was a problem hiding this comment.
What is this sentence which is not finished? I suggest removing it.
doc/api.rst
Outdated
| Format values including the unit. | ||
|
|
||
| .. method:: get_dates() -> (datetime.datetime, datetime.datetime) or None | ||
| .. method:: get_dates() |
Member
There was a problem hiding this comment.
Change unrelated to is_worker(), please revert it.
doc/conf.py
Outdated
|
|
||
| intersphinx_mapping = { | ||
| 'python': ('https://docs.python.org/3', None), | ||
| } |
Member
There was a problem hiding this comment.
Changes unrelated to is_worker().
Author
|
Hi @vstinner , I've reverted the unrelated documentation and configuration changes. The PR now only contains the Runner.is_worker() logic and its relevant documentation. Ready for re-review. |
vstinner
reviewed
Dec 9, 2025
Member
vstinner
left a comment
There was a problem hiding this comment.
The PR title is "Add Runner.is_worker() helper method" but your PR doesn't add the method anymore, but is full of unrelated changes :-(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new helper method Runner.is_worker() as suggested by @vstinner in issue #166.
bench_func() is executed both in the main process and in worker processes.
Only the main process returns a Benchmark object, while worker processes correctly return None.
However, user code currently has no clean way to detect whether it is running in a worker process, which can lead to unexpected None values ending up in lists.
This PR introduces:
✔ Runner.is_worker()
A small utility method that returns True if the current process was started with --worker, and False otherwise.
It simply exposes the existing worker detection logic via a public API, without changing any existing behavior.
This keeps the PR minimal exactly as requested.