PyDev:如何从控制台调用特定于命令的命令(带断点)? [英] PyDev: How to invoke debugging specific command from console (with breakpoints)?

查看:160
本文介绍了PyDev:如何从控制台调用特定于命令的命令(带断点)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我写了一个我想调试的函数。



PyDev通过其高级功能(如断点)帮助调试很多。



设置断点后,单向调试是在 def main()中或刚刚在模块的正文中写入函数的调用,并按按钮。



是否可以从控制台启动该函数的调试会话及其参数? (就像在RStudio或VBA ...)






这个问题与



(即:将控制台连接到调试会话)






编辑(与第二部分相关):



不幸的是,事情的方式,这是预期的...你的代码被'断点,因此控制台无法回答您,也不会在此模式下处于断点的任何评估(您现在只能使用调试器手表/表达式),因此,您的想法是您使用控制台执行的事情,然后如果你想要你可以添加断点,但你只能在离开断点时再次使用控制台。



请注意,如果要使用在断点的上下文中的交互式控制台,不同的方法是选择一个堆栈框架(在调试视图中)>右键单击它> pydev>调试控制台(或者也可以在调试视图中创建一个新的控制台视图,到相同效果的调试会话)。


Suppose I wrote a function, which I want to debug.

PyDev helps debugging a lot with its advanced features, like breakpoints.

After setting the breakpoints, one way of debugging is to write an invocation of the function in def main() or just in the body of the module, and to press the button.

Is it possible to launch a debug session of the function together with its arguments from the console? (Just like in RStudio or VBA...)


This question is a duplicate of pydev: debug in console mode (interactive)?


Update: I really don't know, what is the magic combination of clicks, that make the interactive debugging possible.

Here is what I do, which is not working (on Ubuntu 14.04 and Eclipse 4.4.I20140606-1215 with PyDev 3.6.0.2014062323, Python 3.4.0, IPython 1.2.1)

First try:

First, I create a new PyDev Project:

Then I insert a new .py file with some code on, and create some breakpoints:

Then I right click somewhere on the code, Debug As...->Python run.

And then 2 consoles open, none of them is IPython. The active console is named [Debug console] proba.py. Typing commands into this console doesn't make the computer to execute them.

There is other console available, named just proba.py. This console is fully interactive, although it is not IPython.

This is indeed an interactive debugger. One can step through the code and inspect variables. Unfortunately updating the variables is not supported; if I enter a command a=10 the variable doesn't get updated.

Second try

This time, before launching the debug session let's try starting IPython. After Ctrl+Alt+Enter I choose Console for currently active editor:

Then Python3 (because this is what I need):

After that I have a fully working IPython console.

When I execute the file via execfile, it triggers an error Failed to create input stream: Read timed out:

Although it seems, that stepping through the code works, I cannot access the variables from the IPython console, although it is possible to access them from Variables view:

解决方案

Actually, yes, you can do that in the latest PyDev versions.

You have to enable that in the preferences as explained in:

http://pydev.org/manual_adv_interactive_console.html#full-debug-support-in-interactive-console

(i.e.: Connect console to a debug session)


Edit (related to 2nd part):

Unfortunately, the way things are, this is expected... your code is 'blocked' in a breakpoint and thus the console can't answer to you nor do any evaluation while you're in the breakpoint in this mode (you can only use the debugger watches/expressions at this point), so, the idea is that you use the console to execute things and then if you want you can add a breakpoint, but you can only use the console again when you left the breakpoint.

Note that if you want to use the interactive console in the context of a breakpoint, a different approach would be selecting a stack frame (in the debug view) > right-clicking it > pydev > Debug Console (or you can also in the debug view create a new console view connected to the debug session for the same effect).

这篇关于PyDev:如何从控制台调用特定于命令的命令(带断点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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