psf / pyperf

Toolkit to run Python benchmarks
http://pyperf.readthedocs.io/
MIT License
771 stars 74 forks source link

Fix tracemalloc error when action isn't defined #161

Closed basepi closed 1 year ago

basepi commented 1 year ago

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 commented 1 year ago

Which command line did you use to trigger this error?

basepi commented 1 year ago

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.

basepi commented 1 year ago

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

basepi commented 1 year ago

@vstinner Can we get this merged?