profile and cProfile cannot profile a directory or PEP-441 zip file
#100961
Labels
type-bug
An unexpected behavior, bug, or error
Bug report
Python can execute zip files (PEP-441) and directories directly, e.g.
python code.ziporpython directory, if they're constructed appropriately (such as viazipappor https://github.com/pantsbuild/pex). These don't work withprofileorcProfilemodules, e.g.python -m profile code.zipfails withValueError: source code string cannot contain null bytesandpython -m cProfile directoryfails withIsADirectoryError: [Errno 21] Is a directory: 'directory'.For example: https://gist.github.com/huonw/52574abce4057afd99abb5e4a7f82b61 has a simple
__main__.pyand a zip file that contains it:There's a script that runs all 9 combinations of zip vs. file vs. directory, and no profiling vs.
profilevscProfile. It can be executed via:git clone https://gist.github.com/huonw/52574abce4057afd99abb5e4a7f82b61 cd 52574abce4057afd99abb5e4a7f82b61 ./script.shOutput of
script.sh:Workarounds:
__main__.py, e.g.unzip code.zip -d directory && python -m cProfile directory/__main__.py.__main__.py, e.g.python -m cPorfile directory/__main__.pyYour environment
python -m platform==macOS-12.5.1-arm64-arm-64bitThe text was updated successfully, but these errors were encountered: