Skip to content

Conversation

@amritamishra01
Copy link

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.

Copy link
Member

@vstinner vstinner left a 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...
Copy link
Member

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()
Copy link
Member

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),
}
Copy link
Member

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().

@amritamishra01
Copy link
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.

Copy link
Member

@vstinner vstinner left a 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 :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants