-
Notifications
You must be signed in to change notification settings - Fork 88
Add Runner.is_worker() helper method #222
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?
Conversation
7dc8ff4 to
ab0a4c3
Compare
vstinner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert unrelated changes.
doc/api.rst
Outdated
|
|
||
| .. module:: pyperf | ||
|
|
||
| The module version... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change unrelated to is_worker(), please revert it.
doc/conf.py
Outdated
|
|
||
| intersphinx_mapping = { | ||
| 'python': ('https://docs.python.org/3', None), | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes unrelated to is_worker().
|
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 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.