调试器在“收集数据...”中超时。 [英] Debugger times out at "Collecting data..."

查看:122
本文介绍了调试器在“收集数据...”中超时。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PyCharm( PyCharm Community Edition 2016.2.2;构建#PC-162.1812.1,已构建)调试Python( 3.5 )程序在2016年8月16日; JRE:1.8.0_76-release-b216 x86; JVM:Windows 10上的JetBrains sro的OpenJDK Server VM(code>)



问题:在某些断点处停止时,调试器窗口停留在收集数据,最终导致超时。(带有无法显示框架变量

要显示的数据既不特殊,也不特别大。 PyCharm可以使用它,因为在所述数据的某些值上有条件的断点可以正常工作(程序中断)-看起来收集数据仅用于显示的过程(与操作目的相反)失败了。



当我进入有断点的地方的函数时,其数据会正确显示。当我进入堆栈时(转到调用函数时,我退出了该堆栈,最初希望在其中具有断点)-我再次陷入了收集数据超时的问题。



至少从2005年以来,就同一问题提出了许多问题。有些已经解决,有些没有。修复程序通常是对最新版本(我拥有的)的更新。



我是否可以找到一般方向来修复或解决此问题?一类问题?






编辑:一年后问题仍然存在,仍然没有反应




编辑2018年4月:看来问题出在在2018.1版本中解决了,现在在 print 行上设置断点时挂起的以下代码现在可以工作(我可以看到变量):

 导入线程

def worker():
a = 3
print('hello ')

threading.Thread(target = worker).start()


解决方案

我认为这是由于某些类的默认方法__str __()太冗长而引起的。 Pycharm调用此方法以在遇到断点时显示局部变量,并且在加载字符串时会卡住。
我用来克服此问题的一个技巧是手动编辑导致错误的类,并用__str __()方法替换不太冗长的内容。



例如,它发生在pytorch _TensorBase类(以及扩展它的所有张量类)上,可以通过编辑pytorch源torch / tensor.py来解决,将__str __()方法更改为:

  def __str __(self):
#所有字符串在Python 3中都是unicode,而我们必须在Python2中编码unicode
#字符串。如果不能,请让python决定最好的
#个字符来替换unicode字符。
return str()+’使用.numpy()打印’
#if sys.version_info> (3,):
#return _tensor_str._str(self)
#else:
#if hasattr(sys.stdout,'encoding'):
#return _tensor_str._str (self).encode(
#sys.stdout.encoding或'UTF-8','replace')
#else:
#return _tensor_str._str(self).encode(' UTF-8',替换)

距离最优值还很远,但是在手。



更新:该错误似乎在上一个PyCharm版本(2018.1)中已解决,至少对于影响我的情况而言。


I am debugging a Python (3.5) program with PyCharm (PyCharm Community Edition 2016.2.2 ; Build #PC-162.1812.1, built on August 16, 2016 ; JRE: 1.8.0_76-release-b216 x86 ; JVM: OpenJDK Server VM by JetBrains s.r.o) on Windows 10.

The problem: when stopped at some breakpoints, the Debugger window is stuck at "Collecting data", which eventually timeout. (with Unable to display frame variables)

The data to be displayed is neither special, nor particularly large. It is somehow available to PyCharm since a conditional break point on some values of the said data works fine (the program breaks) -- it looks like the process to gather it for display only (as opposed to operational purposes) fails.

When I step into a function around the place I have my breakpoint, its data is displayed correctly. When I go up the stack (to the calling function, the one I stepped down from and where I wanted initially to have the breakpoint) - I am stuck with the "Collecting data" timeout again.

There have been numerous issues raised with the same point since at least 2005. Some were fixed, some not. The fixes were usually updates to the latest version (which I have).

Is there a general direction I can go to in order to fix or work around this family of problems?


EDIT: a year later the problem is still there and there is still no reaction from the devs/support after the bug was raised.


EDIT April 2018: It looks like the problem is solved in the 2018.1 version, the following code which was hanging when setting a breakpoint on the print line now works (I can see the variables):

import threading

def worker():
    a = 3
    print('hello')

threading.Thread(target=worker).start()

解决方案

I think that this is caused by some classes having a default method __str__() that is too verbose. Pycharm calls this method to display the local variables when it hits a breakpoint, and it gets stuck while loading the string. A trick I use to overcome this is manually editing the class that is causing the error and substitute the __str__() method for something less verbose.

As an example, it happens for pytorch _TensorBase class (and all tensor classes extending it), and can be solved by editing the pytorch source torch/tensor.py, changing the __str__() method as:

def __str__(self):
        # All strings are unicode in Python 3, while we have to encode unicode
        # strings in Python2. If we can't, let python decide the best
        # characters to replace unicode characters with.
        return str() + ' Use .numpy() to print'
        #if sys.version_info > (3,):
        #    return _tensor_str._str(self)
        #else:
        #    if hasattr(sys.stdout, 'encoding'):
        #        return _tensor_str._str(self).encode(
        #            sys.stdout.encoding or 'UTF-8', 'replace')
        #    else:
        #        return _tensor_str._str(self).encode('UTF-8', 'replace')

Far from optimum, but comes in hand.

UPDATE: The error seems solved in the last PyCharm version (2018.1), at least for the case that was affecting me.

这篇关于调试器在“收集数据...”中超时。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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