PyCharm调试器生产线与现实不同步 [英] PyCharm Debugger Lines Are Out Of Sync With Reality

查看:194
本文介绍了PyCharm调试器生产线与现实不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django Rest Framework 3.5.4和Pycharm Professional 2016.3.1。顺便说一句,我将PyCharm配置为在本地无用的盒子内使用virtualenv。



当我在调试器打开的情况下逐步执行DRF代码时,我看到它正在逐步执行空白行,并且调试器中的变量与以下内容不匹配。范围(此处显示 rest_framework.response.Response.rendered_content()):





这是另一个示例,该示例显示调试器中范围内的变量如何与传入的单个变量不匹配。另外,请注意断点是如何清楚地放在文档字符串上:





这不是我第一次在PyCharm中看到这个;在查看库源代码通常可以正常工作时,偶尔我会看到源缓存与正在执行的内容之间不匹配。



我的问题是:如何纠正这种行为?我尝试删除我的virtualenv,然后重新构建它并将其与PyCharm重新关联。我也尝试过 File>使缓存无效/重新启动,在这种情况下,两者都没有帮助。



编辑:



<我以为我已经解决了这个问题,方法是删除所有〜/ Library / Caches / PyCharmXX / remote_sources / *文件,重新使高速缓存无效,重新启动PyCharm,并将远程解释器与项目重新关联。下次尝试调试同一文件时,将显示一个屏幕以选择源。我单击了自动检测,发现有两个版本可用:





我在可用的两者之间做了一个区别,没有区别。此外,每个文件中的字节数和修改时间都相同:

 〜/ Library中pnore-mbp的pnore /缓存
$ 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-mbp in〜/ Library / Caches
$ ls -l PyCharm2016.3 / remote_sources / 974253138 /-328085538/rest_framework/serializers.py
-rw-r--r-- 1 pnore HBS\Domain用户60495 Mar 7 16:56 PyCharm2016.3 / remote_sources / 974253138 / -328085538 / rest_framework / serializers。 py

在〜/ Library / Caches中的pnore-mbp处pnore
$ diff PyCharm2016.3 / remote_sources / 974253138/308149114 / rest_framework / serializers.py PyCharm2016.3 / remote_sources / 974253138 /- 328085538 / rest_framework / serializers.py
[无输出]

我任意选择了后者,然后进行调试ging行号似乎与该文件匹配。我认为问题在于PyCharm的先前版本已将该路径文件与该库的缓存旧版本相关联。我不知道为什么仅凭自己使缓存无效并不能解决问题。



不幸的是,在调试会话期间,该关联并未保留在PyCharm中 。这意味着每个调试会话都需要重新关联每个文件。显然是错误的。

解决方案

在调试配置中设置路径映射


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.

解决方案

set "path mappings" in the debug configuration

这篇关于PyCharm调试器生产线与现实不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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