PyDev.Debugger icon indicating copy to clipboard operation
PyDev.Debugger copied to clipboard

_NormPaths causing issue on unicodes

Open Wilhelmsson177 opened this issue 7 years ago • 4 comments

Hello,

after the latest PyDev update in eclipse to version 6.5.0.201809011628. I have been noticing a strange behavior on def _NormPaths(filename): in PyDev.Debugger/pydevd_file_utils.py.

The check for the str always raises an AssertionError, because a unicode is detected instead. If i comment out the following lines, everything works fine in my case.

if filename.__class__ != str:
    raise AssertionError('Paths passed to _NormPaths must be str. Found: %s (%s)' % (filename, type(filename)))

These two lines are causing the following output for a lot of files when I try to attach to my process, it becomes not responsive anymore.

AssertionError: Paths passed to _NormPaths must be str. Found: C:\Development\project\application\gui\FrmMain.pyo (<type 'unicode'>)
AssertionError: Paths passed to _NormPaths must be str. Found: C:\Development\project\lib\FileMonitor.pyo (<type 'unicode'>)
Traceback (most recent call last):
Traceback (most recent call last):
  File "_pydevd_bundle\pydevd_cython_win32_27_64.pyx", line 1230, in _pydevd_bundle.pydevd_cython_win32_27_64.ThreadTracer.__call__
  File "_pydevd_bundle\pydevd_cython_win32_27_64.pyx", line 1230, in _pydevd_bundle.pydevd_cython_win32_27_64.ThreadTracer.__call__
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 525, in get_abs_path_real_path_and_base_from_frame
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 525, in get_abs_path_real_path_and_base_from_frame
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 503, in get_abs_path_real_path_and_base_from_file
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 503, in get_abs_path_real_path_and_base_from_file
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 337, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 337, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 224, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 224, in _NormPaths

It was working fine with the version before. I don't know if the issue has some other source. If you need any help identifying the issue, please let me know.

Wilhelmsson177 avatar Oct 29 '18 07:10 Wilhelmsson177

This is odd and shouldn't be happening (ThreadTracer uses frame.f_code.co_filename and that should be bytes in Python 2, not unicode -- there's only one place in _pydevd_bundle.pydevd_trace_dispatch_regular.ThreadTracer.__call__ which calls get_abs_path_real_path_and_base_from_frame and it uses frame.f_code.co_filename, so, I'm really puzzled on how that happens and I can't reproduce it here).

You're using the cythonized version of that code from _pydevd_bundle.pydevd_cython_win32_27_64.pyd -- if you rename that file to something else, do you get the same stack trace?

Do you know if there's anything particular to your Python installation or something else which could make frame.f_code.co_filename be a unicode?

fabioz avatar Oct 29 '18 10:10 fabioz

Thank you for the super fast feedback. You're suggestion be renaming the _pydevd_bundle.pydevd_cython_win32_27_64.pyd did not help.

Regarding you're other question: Which Pyton environment do you mean? The tool I want to debug is a python based tool, which ships it's own python environment. The Python installation I select after I have selected the attach to process step is an anaconda based Python 27 installation.

As I said, the same constellation was working fine previously. I also faced the same Issue, with the ptvsd debugger and Microsoft Visual Studio.

@Offtopic: I really like the pydevd extension in Eclipse, but I like the Visual Studio Code as an editor much more than Eclipse. Can you say, if the extension for Visual Studio Code will continue to be developed?

Wilhelmsson177 avatar Oct 30 '18 09:10 Wilhelmsson177

@Wilhelmsson177 which tool are you debugging?

Can you pass me the stack trace when you remove the .pyd? (it should be a little different).

Can you check if running the code below gives str or unicode?

def method():
    import sys
    print(type(sys._getframe().f_code.co_filename))
method()

Regarding the extension for VSCode, it'll continue to be developed ;)

fabioz avatar Oct 30 '18 11:10 fabioz

Hey @fabioz,

I'm debugging ECU-TEST a tool by TraceTronic, which is also a Gold Sponsor of PyDev.

Traceback when .pyd is removed:

Traceback (most recent call last):
AssertionError: Paths passed to _NormPaths must be str. Found: C:\Development\project\threading.pyo (<type 'unicode'>)
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 525, in get_abs_path_real_path_and_base_from_frame
Traceback (most recent call last):
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 503, in get_abs_path_real_path_and_base_from_file
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\_pydevd_bundle\pydevd_trace_dispatch_regular.py", line 282, in __call__
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 503, in get_abs_path_real_path_and_base_from_file
Traceback (most recent call last):
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\_pydevd_bundle\pydevd_trace_dispatch_regular.py", line 282, in __call__
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 337, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 525, in get_abs_path_real_path_and_base_from_frame
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 337, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\_pydevd_bundle\pydevd_trace_dispatch_regular.py", line 282, in __call__
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 525, in get_abs_path_real_path_and_base_from_frame
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 224, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 503, in get_abs_path_real_path_and_base_from_file
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 224, in _NormPaths
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 525, in get_abs_path_real_path_and_base_from_frame
  File "C:/Users/Willi/.p2/pool/plugins/org.python.pydev.core_6.5.0.201809011628/pysrc\pydevd_file_utils.py", line 503, in get_abs_path_real_path_and_base_from_file

The check returns: <type 'str'>.

This whole thing is really strange. I checked with a colleague and he did not have this issue using the newest version and attaching to the same tool.

If you have another idea, please let me know, but don't put to much effort into it.

I'm very excited that the extension for VSCode will continue.

Wilhelmsson177 avatar Oct 30 '18 12:10 Wilhelmsson177