PyCharm Debugger Lines Are Out Of Sync With Reality

放肆的年华 提交于 2020-07-21 04:14:08

问题


I'm using Django Rest Framework 3.5.4 and Pycharm Professional 2016.3.1. Incidentally, I have PyCharm configured to use a virtualenv inside a local vagrant box.

When I step through the DRF code with the debugger on, I can see that it is stepping through blank lines, and the variables in the debugger don't match those in scope (pictured here is rest_framework.response.Response.rendered_content()):

Here's another example that shows how variables in scope in the debugger don't match the single variable passed in. Also, note how the breakpoint is clearly on a docstring:

This is not the first time I have seen this in PyCharm; while viewing the library source usually works, occasionally I will see a mismatch between the source caches and what is being executed.

My question is: how can I correct this behavior? I have tried blowing away my virtualenv and then rebuilding it and reassociating it with PyCharm. I have also tried File > Invalidate Caches / Restart and in this particular case neither have helped.

EDIT:

I thought I had solved this issue by removing all of the ~/Library/Caches/PyCharmXX/remote_sources/* files, re-invalidating the caches, restarting PyCharm, and re-associating the remote interpreter with the project. The next time I tried debugging the same file, I was given a screen to select the sources. I clicked auto-detect and noticed that two versions were available:

I did a diff between the two that were available, and there was no difference. Also, the number of bytes and the modification times were the same in each file:

pnore at pnore-mbp in ~/Library/Caches
$ ls -l PyCharm2016.3/remote_sources/974253138/308149114/rest_framework/serializers.py
-rw-r--r--  1 pnore  HBS\Domain Users  60495 Mar  7 16:56 PyCharm2016.3/remote_sources/974253138/308149114/rest_framework/serializers.py

pnore at pnore-mbp in ~/Library/Caches
$ ls -l PyCharm2016.3/remote_sources/974253138/-328085538/rest_framework/serializers.py
-rw-r--r--  1 pnore  HBS\Domain Users  60495 Mar  7 16:56 PyCharm2016.3/remote_sources/974253138/-328085538/rest_framework/serializers.py

pnore at pnore-mbp in ~/Library/Caches
$ diff PyCharm2016.3/remote_sources/974253138/308149114/rest_framework/serializers.py PyCharm2016.3/remote_sources/974253138/-328085538/rest_framework/serializers.py
[no output]

I arbitrarily chose the latter one, and subsequently, debugging line numbers appeared to match up for that file. I believe the problem was that a previous version of PyCharm had associated that path file with a cached old version of the library. I do not know why invalidate caches on its own did not solve the issue.

Unfortunately, the association does NOT remain in PyCharm across debugging sessions. This means that the every file needs to be re-associated for every debugging session; something is clearly wrong.


回答1:


I had a similar issue, two files with the same path and the debugger was using the wrong one, though in my case the files did differ slightly.

The fix was as follows on Windows with PyCharm 2017.2.3:

  1. Exit PyCharm.
  2. Remove folders leftover from previous versions of PyCharm. In my case there was both .PyCharm2017.2 and .PyCharm2017.1 folders.
  3. Restart PyCharm.
  4. Debug again, select auto-detect when prompted to select the correct source.



回答2:


set "path mappings" in the debug configuration



来源:https://stackoverflow.com/questions/42651430/pycharm-debugger-lines-are-out-of-sync-with-reality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!