0

I'm trying to setup a good VSCode python environment for debugging including profiling using cProfile in a REPL manner, and I really like the debug widow.

In the VSCode debugger I am able to run/debug the following script:

import cProfile

cProfile.run("10 + 10")
print("Break here")

I am using the Microsoft "Python" extension for debugging and setting the output to "internalConsole" in my "launch.json" and the cProfile output correctly shows up in the debug console window.

However, after hitting a breakpoint set at print("Break here") and manually entering the command cProfile.run("10 + 10") into the debug console window, I get the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.8/cProfile.py", line 16, in run
    return _pyprofile._Utils(Profile).run(statement, filename, sort)
  File "/usr/lib/python3.8/profile.py", line 57, in run
    self._show(prof, filename, sort)
  File "/usr/lib/python3.8/profile.py", line 72, in _show
    prof.print_stats(sort)
  File "/usr/lib/python3.8/cProfile.py", line 42, in print_stats
    pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
  File "/usr/lib/python3.8/pstats.py", line 96, in __init__
    self.init(arg)
  File "/usr/lib/python3.8/pstats.py", line 110, in init
    self.load_stats(arg)
  File "/usr/lib/python3.8/pstats.py", line 136, in load_stats
    raise TypeError("Cannot create or construct a %r object from %r"
TypeError: Cannot create or construct a <class 'pstats.Stats'> object from <cProfile.Profile object at 0x7efee11c30a0>

I am also able to run cProfile.run("10 + 10") in a command line python session as well as in the VSCode terminal ("integratedTerminal").

Any ideas on how to fix this and why the behavior is different for the debug console window?

I tried searching information regarding the mechanisms of the debug window in comparison with terminal window but have not found anything of substance yet.

grescha
  • 3
  • 1
  • 2

0 Answers0