是否可以在PTVS的交互式窗口中调试调用的方法? [英] Is it possible to debug a method called from the interactive window in PTVS?

查看:165
本文介绍了是否可以在PTVS的交互式窗口中调试调用的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Python开发时,我经常要调试特定的方法,在这种情况下,可以从交互式控制台调用该方法或调试交互式控制台.但是,当从PTVS的交互式窗口中调用某个方法时,该方法不会在该方法的断点处停止.

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. However, when a method is called from the interactive windows in PTVS, it doesn't stop at the break points in said method.

如果可能的话,请告诉我该怎么做.如果没有,我想请求此功能,并且想知道是否有比从主脚本中调用特定方法更快的方法来调试特定方法.

If it's possible, please tell me how to do it. If not, I would like to request this feature, and also to know if there is any quicker way to debug a specific method than calling it from the main script.

我在Visual Studio 2013 Ultimate中使用PTVS 2.0 RC

I'm using PTVS 2.0 RC in Visual Studio 2013 Ultimate

推荐答案

在使用常规(非调试)"Python交互式"窗口时,实际上可以通过使用Debug->将VS附加到正在运行的python.exe进程中.附加到流程.一旦完成,如果交互式窗口做了一些事情,例如碰到一个断点,调试器就会碰到那个断点.

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.

棘手的部分是通过解决断点的方式从文件中加载代码.特别是,$load REPL命令将不起作用,因为它只是读取文件并逐行在REPL中进行评估,而不保留原始文件上下文.您需要使用Python工具加载脚本-例如importopen + exec.

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.

那里也有一些陷阱-例如每当您在断点处暂停时,REPL窗口将无响应.

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

这篇关于是否可以在PTVS的交互式窗口中调试调用的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆