pprofile icon indicating copy to clipboard operation
pprofile copied to clipboard

pprofile executing wrong Python file

Open MatthijsdeJ opened this issue 3 years ago • 1 comments

My aim with pprofile was to perform statistic profiling of the execution of generate_imitation_data.py, excluding all files but two: imitation_generation/generation.py and imitation_generation/tutor.py. I ran the command:

pprofile -o profile_out.txt --statistic 0.01 --exclude *.py --include imitation_generation/generation.py --include imitation_generation/tutor.py generate_imitation_data.py

However, executing this command executes a different python file in my directory: preprocess_data.py.

MatthijsdeJ avatar Feb 01 '22 08:02 MatthijsdeJ

The reason is the *.py pattern: this gets expanded by your shell before the call, which likely results in something like --exclude some.py preprocess_data.py some_other.py (etc), which, as of the current code, ends the named argument list (some.py being the only value applied to --exclude). Which means that from preprocess_data.py on, these arguments get assigned to the SCRIPT positional arguments, everything after it becoming the sys.argv value of preprocess_data.py.

A solution is to convert the glob syntax into an all-matching regex, and the shell should leave it alone:

pprofile -o profile_out.txt --statistic 0.01 --exclude '' --include imitation_generation/generation.py --include imitation_generation/tutor.py generate_imitation_data.py

But this is already what pprofile does internally if you only provide the --include argument, so it should be possible to leave --exclude out entirely.

vpelletier avatar Feb 02 '22 00:02 vpelletier