Skip to content
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

Fix tracemalloc error when action isn't defined #161

Merged
merged 3 commits into from
Jun 11, 2023

Conversation

basepi
Copy link
Contributor

@basepi basepi commented May 11, 2023

Ref #131

We're using the Runner's argument parsing, but without using pyperf directly. This is resulting in an undefined action, which means that when we use the --tracemalloc argument, we get the following error:

  File ".../python3.8/site-packages/pyperf/_runner.py", line 334, in _process_args_impl

    if args.action == 'command':

AttributeError: 'Namespace' object has no attribute 'action'

This PR checks for the attribute before accessing it.

@vstinner
Copy link
Member

Which command line did you use to trigger this error?

@basepi
Copy link
Contributor Author

basepi commented May 12, 2023

We're triggering the runner with our own script. That script calls another script with the relevant pyperf args (such as --tracemalloc), which we parse here. The actual pyperf invocation we're using is runner.bench_func().

It's an odd way of invoking pyperf, I'll be the first to admit. This is legacy code I've been slowly cleaning up and modernizing. Perhaps using parse_args() this way without actually using the pyperf command is not supported. But it worked until #131. That is the only place in the arg handling code where args.action is accessed, so upgrading pyperf resulted in an AttributeError for us.

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.

Oh right, I can reproduce the issue with python3 doc/examples/bench_func.py --tracemalloc command.

pyperf/_runner.py Outdated Show resolved Hide resolved
Co-authored-by: Victor Stinner <[email protected]>
@basepi basepi requested a review from vstinner May 15, 2023 14:05
@basepi
Copy link
Contributor Author

basepi commented May 22, 2023

@vstinner Is there anything else pending here that I can help with?

@basepi
Copy link
Contributor Author

basepi commented Jun 7, 2023

@vstinner Can we get this merged?

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@corona10 corona10 merged commit f4db461 into psf:main Jun 11, 2023
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.

3 participants