Add Runner.is_worker() helper method #222
Open
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.