简体   繁体   English

pydev断点不起作用

[英]pydev breakpoints not working

I am working on a project using python 2.7.2, sqlalchemy 0.7, unittest, eclipse 3.7.2 and pydev 2.4. 我正在使用python 2.7.2,sqlalchemy 0.7,unittest,eclipse 3.7.2和pydev 2.4进行项目。 I am setting breakpoints in python files (unit test files), but they are completely ignored (before, at some point, they worked). 我在python文件(单元测​​试文件)中设置断点,但它们被完全忽略(之前,在某些时候,它们工作)。 By now i have upgraded all related software (see above), started new projects, played around with settings, hypnotized my screen, but nothing works. 到目前为止,我已升级所有相关软件(见上文),启动新项目,玩设置,催眠我的屏幕,但没有任何作用。

The only idea i got from some post is that it has something to de with changing some .py file names to lower case. 我从一些帖子得到的唯一想法是,它有一些东西可以将一些.py文件名改为小写。

Does anyone have any ideas? 有没有人有任何想法?

added: I even installed the aptana version of eclipse and copied the .py files to it => same result; 补充:我甚至安装了eclipse的aptana版本并将.py文件复制到它=>相同的结果; breakpoints are still ignored. 断点仍然被忽略。

still no progress: I have changed some code that might be seen as unusual and replaced it with a more straightforward solution. 仍然没有进展:我已经改变了一些可能被视为不寻常的代码,并用更简单的解决方案取而代之。

some more info: it probably has something to do with module unittest: 更多信息:它可能与模块unittest有关:

  • breakpoints in my files defining test suites work, 定义测试套件的文件中的断点有效,
  • breakpoints in the standard unittest files themselves work 标准单元测试文件中的断点本身有效
  • breakpoints in my tests methods in classes derived from unittest.TestCase do not work 从unittest.TestCase派生的类中的测试方法中的断点不起作用
  • breakpoints in my code being tested in the test cases do not work 我在测试用例中测试的代码中的断点不起作用
  • at some point before i could define working breakpoints in test methods or the code being tested 在我可以在测试方法或正在测试的代码中定义工作断点之前的某个时刻
  • some things i changed after that are: started using test suites, changed some filenames to lowercase, ... 之后我改变了一些事情:开始使用测试套件,将一些文件名改为小写,......
  • this problem also occurs if my code works without exceptions or test failures. 如果我的代码无异常或测试失败,也会出现此问题。

what I already tried is: 我已经尝试过的是:

  • remove .pyc files 删除.pyc文件
  • define new project and copy only .py files to it 定义新项目并仅将.py文件复制到其中
  • rebooted several times in between 中间重启几次
  • upgraded to eclipse 3.7.2 升级到eclipse 3.7.2
  • installed latest pydev on eclipse 3.7.2 在eclipse 3.7.2上安装了最新的pydev
  • switch to aptana (and back) 切换到aptana(和后面)
  • removed code that 'manually' added classes to my module 删除了“手动”将类添加到我的模块的代码
  • fiddled with some configurations 摆弄一些配置

what I can still do is: 我还能做的是:

  • start new project with my code, start removing/changing code until breakpoints work and sort of black box figure out if this has something to do with some part of my code 用我的代码启动新项目,开始删除/更改代码,直到断点工作,并且黑盒子的排序是否与我的代码的某些部分有关

  • Does anyone have any idea what might cause these problems or how they might be solved? 有谁知道可能导致这些问题的原因或如何解决这些问题?
  • Is there any other place i could look for a solution? 还有其他地方我可以寻找解决方案吗?
  • Do pydev developers look into the questions on stackoverflow? pydev开发人员是否会查看stackoverflow上的问题?
  • Is there an older version of pydev that i might try? 我可能会尝试使用较旧版本的pydev吗?

I have been working with pydev/eclipse for a long time and it works well for me, but without debugging i'd forced to switch IDE. 我一直在使用pydev / eclipse很长一段时间,它对我很有用,但没有调试我就被迫切换IDE。

In answer to Fabio's questions below: 回答下面Fabio的问题:

  • The python version is 2.7.2, python版本是2.7.2,
  • The sys.gettrace gives None (but I have no idea what in my code could influence that) sys.gettrace给出None(但我不知道我的代码会对它产生什么影响)
  • This is the output of the debugger after changing the suggested parameters: 这是更改建议参数后调试器的输出:

pydev debugger: pydev调试器:

starting
('Executing file ', 'D:\\.eclipse\\org.eclipse.platform_3.7.0_248562372\\plugins\\org.python.pydev.debug_2.4.0.2012020116\\pysrc\\runfiles.py')
('arguments:', "['D:\\\\.eclipse\\\\org.eclipse.platform_3.7.0_248562372\\\\plugins\\\\org.python.pydev.debug_2.4.0.2012020116\\\\pysrc\\\\runfiles.py', 'D:\\\\Documents\\\\Code\\\\Eclipse\\\\workspace\\\\sqladata\\\\src\\\\unit_test.py', '--port', '49856', '--verbosity', '0']")
('Connecting to ', '127.0.0.1', ':', '49857')
('Connected.',)
('received command ', '501\t1\t1.1')
sending cmd: CMD_VERSION 501    1   1.1

sending cmd: CMD_THREAD_CREATE 103  2   <xml><thread name="pydevd.reader" id="-1"/></xml>

sending cmd: CMD_THREAD_CREATE 103  4   <xml><thread name="pydevd.writer" id="-1"/></xml>

('received command ', '111\t3\tD:\\Documents\\Code\\Eclipse\\workspace\\sqladata\\src\\testData.py\t85\t**FUNC**testAdjacency\tNone')
Added breakpoint:d:\documents\code\eclipse\workspace\sqladata\src\testdata.py - line:85 - func_name:testAdjacency
('received command ', '122\t5\t;;')
Exceptions to hook : []
('received command ', '124\t7\t')
('received command ', '101\t9\t')
Finding files... done.
Importing test modules ... testAtomic (testTypes.TypeTest) ... ok
testCyclic (testTypes.TypeTest) ... 

The rest is output of the unit test. 其余的是单元测试的输出。

Continuing from Fabio's answer part 2: 继Fabio的回答第2部分:

I have added the code at the start of the program and the debugger stops working at the last line of following the method in sqlalchemy\\orm\\attributes.py (it is a descriptor, but how or whther it interferes with the debugging is beyond my current knowledge): 我在程序开始时添加了代码,调试器在sqlalchemy \\ orm \\ attributes.py中跟随方法的最后一行停止工作(它是一个描述符,但它如何或者干扰调试是否超出我的范围目前的知识):

class InstrumentedAttribute(QueryableAttribute): """Class bound instrumented attribute which adds descriptor methods.""" class InstrumentedAttribute(QueryableAttribute):“”“类绑定的检测属性,它添加描述符方法。”“”

def __set__(self, instance, value):
    self.impl.set(instance_state(instance), 
                    instance_dict(instance), value, None)

def __delete__(self, instance):
    self.impl.delete(instance_state(instance), instance_dict(instance))

def __get__(self, instance, owner):
    if instance is None:
        return self

    dict_ = instance_dict(instance)
    if self._supports_population and self.key in dict_:
        return dict_[self.key]
    else:
        return self.impl.get(instance_state(instance),dict_) #<= last line of debugging

From there the debugger steps into the __getattr__ method of one of my own classes, derived from a declarative_base() class of sqlalchemy. 从那里调试器进入我自己的一个类的__getattr__方法,该方法派生自sqlalchemy的declarative_base()类。

Probably solved (though not understood): 可能解决了(尽管不了解):

The problem seemed to be that the __getattr__ mentioned above, created something similar to infinite recursion, however the program/unittest/sqlalchemy recovered without reporting any error. 问题似乎是上面提到的__getattr__ ,创建了类似于无限递归的东西,但是program / unittest / sqlalchemy在没有报告任何错误的情况下恢复了。 I do not understand the sqlalchemy code sufficiently to understand why the __getattr__ method was called. 我不太了解sqlalchemy代码,无法理解调用__getattr__方法的原因。
I changed the __getattr__ method to call super for the attribute name for which the recursion occurred (most likely not my final solution) and the breakpoint problem seems gone. 我更改了__getattr__方法,为发生递归的属性名称调用super(很可能不是我的最终解决方案),并且断点问题似乎消失了。 If i can formulate the problem in a consise manner, i will probably try to get some more info on the google sqlalchemy newsgroup, or at least check my solution for robustness. 如果我能以一种简明的方式表达问题,我可能会尝试在google sqlalchemy新闻组上获得更多信息,或至少检查我的解决方案的稳健性。

Thank you Fabio for your support, the trace_func() function pinpointed the problem for me. 谢谢Fabio的支持,trace_func()函数为我找到了问题所在。

Seems really strange... I need some more info to better diagnose the issue: 看起来很奇怪...我需要更多信息来更好地诊断问题:

Open \\plugins\\org.python.pydev.debug\\pysrc\\pydevd_constants.py and change 打开\\ plugins \\ org.python.pydev.debug \\ pysrc \\ pydevd_constants.py并更改

DEBUG_TRACE_LEVEL = 3 
DEBUG_TRACE_BREAKPOINTS = 3

run your use-case with the problem and add the output to your question... 运行您的用例与问题,并将输出添加到您的问题...

Also, it could be that for some reason the debugging facility is reset in some library you use or in your code, so, do the following: in the same place that you'd put the breakpoint do: 此外,可能由于某种原因,调试工具在您使用的某个库或代码中被重置,因此,请执行以下操作:在您放置断点的同一位置执行:

import sys
print 'current trace function', sys.gettrace()

(note: when running in the debugger, it'd be expected that the trace function is something as: <bound method PyDB.trace_dispatch of <__main__.PyDB instance at 0x01D44878>> ) (注意:在调试器中运行时,可以预期跟踪函数是这样的: <bound method PyDB.trace_dispatch of <__main__.PyDB instance at 0x01D44878>>

Also, please post which Python version you're using. 另外,请发布您正在使用的Python版本。


Answer part 2: 答案第2部分:

The fact that sys.gettrace() returns None is probably the real issue... I know some external libraries which mess with it (ie:DecoratorTools -- read: http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html ) and have even seen Python bugs and compiled extensions break it... sys.gettrace()返回None的事实可能是真正的问题......我知道一些外部库与它混乱(即:DecoratorTools - 阅读: http//pydev.blogspot.com/2007/06/why -cant-pydev-debugger-work-with.html )甚至看到Python错误和编译的扩展打破了它...

Still, the most common reason it breaks is probably because Python will silently disable the tracing (and thus the debugger) when a recursion throws a stack overflow error (ie: RuntimeError: maximum recursion depth exceeded). 尽管如此,它最常见的原因可能是因为当递归引发堆栈溢出错误 (即:RuntimeError:超出最大递归深度)时, Python会默默地禁用跟踪(以及调试器 )。

You can probably put a breakpoint in the very beginning of your program and step in the debugger until it stops working. 您可以在程序的最开始处放置断点并进入调试器,直到它停止工作。

Or maybe simpler is the following: Add the code below to the very beginning of your program and see how far it goes with the printing... The last thing printed is the code just before it broke (so, you could put a breakpoint at the last line printed knowing it should be the last line where it'd work) -- note that if it's a large program, printing may take a long time -- it may even be faster printing to a file instead of a console (such as cmd, bash or eclipse) and later opening that file (just redirect the print from the example to a file). 或者可能更简单如下:将下面的代码添加到程序的最开头,看看它与打印的距离......打印的最后一件事就是它破坏前的代码(所以,你可以设置断点)打印的最后一行知道它应该是它工作的最后一行 - 请注意,如果它是一个大型程序,打印可能需要很长时间 - 甚至可能更快打印到文件而不是控制台(如如cmd,bash或eclipse)以及稍后打开该文件(只是将打印从示例重定向到文件)。

import sys

def trace_func(frame, event, arg):
    print 'Context: ', frame.f_code.co_name, '\tFile:', frame.f_code.co_filename, '\tLine:', frame.f_lineno, '\tEvent:', event
    return trace_func

sys.settrace(trace_func)

If you still can't figure it out, please post more information on the obtained results... 如果您仍然无法弄清楚,请在获得的结果上发布更多信息......

Note: a workaround until you don't find the actual place is using: 注意:在您找不到实际位置之前的解决方法是使用:

import pydevd;pydevd.settrace()

on the place where you'd put the breakpoint -- that way you'd have a breakpoint in code which should definitely work, as it'll force setting the tracing facility at that point (it's very similar to the remote debugging: http://pydev.org/manual_adv_remote_debugger.html except that as the debugger was already previously connected, you don't really have to start the remote debugger, just do the settrace to emulate a breakpoint) 在你放置断点的地方 - 这样你就会在代码中有一个断点,这肯定会起作用,因为它会强制在那时设置跟踪工具(它与远程调试非常相似: http:http: //pydev.org/manual_adv_remote_debugger.html除了因为调试器之前已连接过,你不必真正启动远程调试器,只需执行settrace来模拟断点)

Coming late into the conversation, but just in case it helps. 迟到的谈话,但以防万一它有所帮助。 I just run into a similar problem and I found that the debugger is very particular wrt what lines it considers "executable" and available to break on. 我遇到了类似的问题,我发现调试器非常特别,它认为是“可执行”的行,并且可用于中断。

If you are using line continuations, or multi-line expressions (eg inside a list), put the breakpoint in the last line of the statement. 如果使用行连续符或多行表达式(例如,在列表中),请将断点放在语句的最后一行。

I hope it helps. 我希望它有所帮助。

Try removing the corresponding .pyc file (compiled) and then running. 尝试删除相应的.pyc文件(已编译)然后运行。 Also I have sometimes realized I was running more than one instance of a program.. which confused pydev. 此外,我有时意识到我正在运行一个以上的程序实例..这使pydev感到困惑。 I've definitely seen this before too. 我以前也一定见过这个。 Quite a few times. 好几次。

Ran into a similar situation running a django app in Eclipse/pydev. 在Eclipse / pydev中运行django应用程序的类似情况。 what was happening was that the code that was running was the one installed in my virtualenv, not my source code. 发生的事情是运行的代码是我的virtualenv中安装的代码,而不是我的源代码。 I removed my project from my virtual env site-packages, restarted the django up in the eclipse/pydev debugger and everything was fine. 我从我的虚拟env站点包中删除了我的项目,在eclipse / pydev调试器中重新启动了django,一切都很好。

I had similar-sounding symptoms. 我有类似的症状。 It turned out that my module import sequence was rexec'ing my entry-point python module because a binary (non-Python) library had to be dynamically loaded, ie, the LD_LIBRARY_PATH was dynamically reset. 原来我的模块导入序列是rexec'ing我的入口点python模块,因为必须动态加载二进制(非Python)库,即LD_LIBRARY_PATH被动态重置。 I don't know why this causes the debugger to ignore subsequent breakpoints. 我不知道为什么这会导致调试器忽略后续断点。 Perhaps the rexec call is not specifying debug=true; 也许rexec调用没有指定debug = true; it should specify debug=true/false based on the calling context state? 它应该根据调用上下文状态指定debug = true / false?

Try setting a breakpoint at your first import statement being cognizant of whether you are then s(tep)'ing into or n(ext)'ing over the imports. 尝试在您的第一个导入语句中设置一个断点,认识到您是否在进口时进入或者进入n(分机)。 When I would "next" over the 3rdparty import that required the dynamic lib loading, the debug interpreter would just continue past all breakpoints. 当我在需要动态lib加载的第3方导入上“下一步”时,调试解释器将继续经过所有断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM