pyperf icon indicating copy to clipboard operation
pyperf copied to clipboard

Add Runner.is_worker() helper method

Open amritamishra01 opened this issue 1 month ago • 0 comments

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.

amritamishra01 avatar Nov 22 '25 18:11 amritamishra01