Is it possible to debug a method called from the interactive window in PTVS?

后端 未结 1 886
抹茶落季
抹茶落季 2021-01-25 03:16

When I\'m developing in Python I often want to debug a specific method, in which case it makes sense to call the method from the interactive console or debug interactive console

相关标签:
1条回答
  • 2021-01-25 03:42

    When using the regular (non-debug) Python Interactive window, you can actually attach VS to the python.exe process that it is running by using Debug -> Attach to Process. Once that is done, if the interactive window does something to e.g. hit a breakpoint, the debugger will hit on that breakpoint.

    The tricky part is loading the code from a file in such a way that breakpoints are resolved. In particular, $load REPL command will not work because it just reads the file and evals it in the REPL line by line, without preserving the original file context. What you need is to load your script using Python facilities - e.g. import, or open+exec.

    There are also some gotchas there - e.g. the REPL window will become unresponsive whenever you are paused on a breakpoint.

    0 讨论(0)
提交回复
热议问题