Repository navigation
profiling.sampling is not working for replay mode #148225
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
I ran next command with a.py code, and it made the error.
python3.15 -m profiling.sampling run -o output.prof a.py
python3.15 -m profiling.sampling replay output.prof
# a.py
for i in range(10000):
a = [*p for p in [[1, 2], [2], [3, 4, 4]]]This is the error message:
Traceback (most recent call last):
File "<frozen runpy>", line 196, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File "C:\Users\XXX\AppData\Local\Python\pythoncore-3.15-64\Lib\profiling\sampling\__main__.py", line 65, in <module>
main()
~~~~^^
File "C:\Users\XXX\AppData\Local\Python\pythoncore-3.15-64\Lib\profiling\sampling\cli.py", line 788, in main
_main()
~~~~~^^
File "C:\Users\XXX\AppData\Local\Python\pythoncore-3.15-64\Lib\profiling\sampling\cli.py", line 922, in _main
handler(args)
~~~~~~~^^^^^^
File "C:\Users\XXX\AppData\Local\Python\pythoncore-3.15-64\Lib\profiling\sampling\cli.py", line 1175, in _handle_replay
with BinaryReader(args.input_file) as reader:
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "C:\Users\XXX\AppData\Local\Python\pythoncore-3.15-64\Lib\profiling\sampling\binary_reader.py", line 32, in __enter__
self._reader = _remote_debugging.BinaryReader(self.filename)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
ValueError: Invalid magic number: 0xfa03a97b
The reported magic number 0xfa03a97b corresponds to Python 3.13/3.14. It seems that profiling.sampling might be inadvertently picking up components or generating data using the 3.14 environment available on the PATH, even when explicitly invoked with python3.15.
I used python 3.15.0a7, and I also downloaded python 3.14.3, and only 3.14.3 is on PATH.
Environments - Window 11 64bit, Using VSCode powershell terminal, pwsh 7.5.5
Also, I tried to do this in venv but python -m profiling.sampling run -o output.prof a.py made another error.
Failed to find the PyRuntime section in process 15236 on Windows platform
CPython versions tested on:
3.15
Operating systems tested on:
Windows
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
Ignyra commentedon Apr 7, 2026
I looked into this a bit, and it seems that the initial error comes from reading the data as the binary format while the original command produced a default
pstatsoutput. Thereplaycommand only works with binary format files that can be generated using--binary, and it doesn’t validate the input format, so passing apstatsfile leads to the confusing error in which theBinaryReaderexpected a magic number in the header where it is only generated for binary files. I think this should work as expected:seanleeee13 commentedon Apr 7, 2026
I tried to do with
--binaryoption, and it madeFailed to find the PyRuntime section in process 26260 on Windows platformerror, a simmilar error with when using venv.seanleeee13 commentedon Apr 7, 2026
Tried with another
a.py- and it worked.I think it could be an error because
a.pyis to short for sampling.Also, I updated to python 3.15.0a8, but it doesn't work on venv yet.
Ignyra commentedon Apr 8, 2026
I tried to reproduce this on Windows with Python 3.15.0a8, but I wasn’t able to hit the same error. It might be related to something environment-specific.
pythongh-148225: Validate profiling.sampling replay input
pythongh-148225: Validate profiling.sampling replay input
pythongh-148225: Validate profiling.sampling replay input
pablogsal commentedon Apr 8, 2026
Yeah I think the only bug here that we can validate is that the binary files are not validated before checking and the error is confusing. I will work on a fix
pythongh-148225: Validate profiling.sampling replay input
gh-148225: Validate profiling.sampling replay input (#148243)
pablogsal commentedon Apr 9, 2026
Thanks for the report!
pythongh-148225: Validate profiling.sampling replay input (python#148243