Debugger times out at “Collecting data…”

后端 未结 6 1721
梦如初夏
梦如初夏 2021-01-31 08:04

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-releas

6条回答
  •  青春惊慌失措
    2021-01-31 08:55

    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.

提交回复
热议问题