我在开发环境中着手进行了一个雄心勃勃的项目,因为我想保持最新状态。因此,我多年来一直在使用Eclipse和PyDev进行Django项目,并且效果很好。
我使用Python 3.7,Django 2.1和Eclipse Photon已有一段时间。
我尝试了一种全新的尝试,如下所示,移至最新版本:
Copy projects into workspace
这很好。首先,我可以使用指向http://127.0.0.1:8000/的网站进行工作,并且该网站大部分都可以正常运行,实际上不能抱怨,几乎可以预期会有更多戏剧性的升级。为了达到与Django 3.0.1兼容的目的,还有些不完善的调整,但令人惊讶的是很少。
虽然我卡在了崩溃的页面上,所以我设置一个断点只是为了发现它不起作用...嗯。我之前曾在PyDev和其他许多人一起来过。因此,我已经执行了基本的诊断,并将分享我的知识。但是,如果有人(尤其是法比奥)有更多的智慧可以借给他们工作,我将不胜感激。
安装在Eclipse上的是:
PyDev for Eclipse 7.4.0.201910251334 org.python.pydev.feature.feature.group Fabio Zadrozny PyDev for Eclipse Developer Resources 7.4.0.201910251334 org.python.pydev.feature.source.feature.group Fabio Zadrozny Pydev Mylyn Integration 0.6.0 org.python.pydev.mylyn.feature.feature.group Fabio Zadrozny
主要观察结果:
Fabio在这里留下了一些非常好(现在是约会)的提示:pydev breakpoints not working,我可以回应一下:
import sys
print('DEBUG: current trace function', sys.gettrace())
我看到此输出:
DEBUG: current trace function None
这似乎是问题所在。某些东西正在关闭调试。
[按照法比奥的第一个技巧,并考虑了自该技巧以来PyDev结构的变化,我在pydevd_constants.py
中发现了plugins/org.python.pydev.core_7.4.0.201910251334/pysrc/_pydevd_bundle
,并且可以设置:
DEBUG_TRACE_LEVEL = 3 DEBUG_TRACE_BREAKPOINTS = 3
如Fabio所建议。这揭示了一点遗憾。从本质上讲,在启动调试运行直到服务器运行之前,我会看到很多不错的跟踪。然后我看到标准输出说服务器现在正在运行:
System check identified no issues (0 silenced). December 26, 2019 - 12:29:54 Django version 3.0.1, using settings 'MyProject.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
在此过程中,它在settings.py中的断点处停止,我继续使用F8。
现在在浏览器中,我正在加载正在调试的视图。而且控制台上的PyDev迹线为零,实际上,我只得到了我打印的小行,将其放入视图的get_queryset()方法中以确保我的代码(带有断点)正在运行。
因此没有任何帮助。我可以在自己的views.py文件中查找与Fabio的建议有关的干草堆:
import sys print('DEBUG: current trace function', sys.gettrace()) def trace_func(frame, event, arg): with open('pydev-trace.txt', 'a') as f: print('Context: ', frame.f_code.co_name, '\tFile:', frame.f_code.co_filename, '\tLine:', frame.f_lineno, '\tEvent:', event, file=f) return trace_func sys.settrace(trace_func) print('DEBUG: current trace function', sys.gettrace())
并且现在在控制台上看到:
DEBUG: current trace function None DEBUG: current trace function <function trace_func at 0x7ffaa6f18b80> System check identified no issues (0 silenced). December 26, 2019 - 12:42:48 Django version 3.0.1, using settings 'MyProject.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
哪种看起来不错。
但是输出跟踪似乎从未停止过。它不断增长,不断增长,似乎陷入了无尽循环的自动重载循环中:
Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 370 Event: call Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 361 Event: line Context: watched_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 260 Event: call Context: watched_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 260 Event: return Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 362 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 758 Event: call Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 759 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: return Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 364 Event: line Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 365 Event: line Context: stat File: /usr/lib/python3.8/pathlib.py Line: 1186 Event: call Context: stat File: /usr/lib/python3.8/pathlib.py Line: 1191 Event: line Context: __fspath__ File: /usr/lib/python3.8/pathlib.py Line: 721 Event: call Context: __fspath__ File: /usr/lib/python3.8/pathlib.py Line: 722 Event: line Context: __str__ File: /usr/lib/python3.8/pathlib.py Line: 711 Event: call Context: __str__ File: /usr/lib/python3.8/pathlib.py Line: 714 Event: line Context: __str__ File: /usr/lib/python3.8/pathlib.py Line: 715 Event: line Context: __str__ File: /usr/lib/python3.8/pathlib.py Line: 715 Event: return Context: __fspath__ File: /usr/lib/python3.8/pathlib.py Line: 722 Event: return Context: stat File: /usr/lib/python3.8/pathlib.py Line: 1191 Event: return Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 369 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 758 Event: call Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 759 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: return Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 370 Event: line Context: snapshot_files File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 370 Event: return Context: tick File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 346 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 758 Event: call Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 759 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: return Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 753 Event: call Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 754 Event: line Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 756 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 744 Event: call Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 747 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: return Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 744 Event: call Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 747 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: return Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 756 Event: return Context: tick File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 347 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 758 Event: call Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 759 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: line Context: __hash__ File: /usr/lib/python3.8/pathlib.py Line: 760 Event: return Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 753 Event: call Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 754 Event: line Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 756 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 744 Event: call Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 747 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: return Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 744 Event: call Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 747 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: line Context: _cparts File: /usr/lib/python3.8/pathlib.py Line: 748 Event: return Context: __eq__ File: /usr/lib/python3.8/pathlib.py Line: 756 Event: return Context: tick File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 348 Event: line Context: tick File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 351 Event: line Context: tick File: /home/me/.local/lib/python3.8/site-packages/django/utils/autoreload.py Line: 345 Event: line
这是我们迄今为止最好的线索。我怀疑这里的事情处于一个非常紧迫的无限循环中。网页仍然加载,因此它不会以惊人的速度消耗资源,并且运行了很长时间,并且不会溢出任何堆栈或任何东西,但显然似乎以某种方式损坏了。
但是在这里很难固定一些东西。
最后在回应中,Fabio建议使用暴力破解方法:
import pydevd; pydevd.settrace()
A无法导入pydevd,但是如果我将其添加到我的外部库中:
...plugins/org.python.pydev.core_7.4.0.201910251334/pysrc
我可以,然后运行它,但是它会在控制台上产生无尽的文本流,并且在这种情况下我的网站将不会响应。因此,在调试服务器宕机的情况下,这是蛮力的;-)。这可能与上面的无尽循环有关。
其他检查:
我检查了Fabios的需求清单:
http://www.pydev.org/manual_adv_django.html
和那些我都很好。
我可以在Project Properties
至此,我希望获得更多的指导。我在这里花费了大量的时间进行诊断,并试图找出原因,但是在这一点上,我的效率将因注入的专业知识和建议而飞速增长。法比奥?
我在这里问的主要是因为有许多其他方面,对于面临类似问题的任何人来说,它都是非常有用的可找到的资源。而且没有理由相信这种情况是不可能的。所以我想解决这个问题,并且基本上出于我和其他人的考虑发布了一个解决方案。
我在开发环境中着手进行了一个雄心勃勃的项目,因为我想保持最新状态。因此,我多年来一直在使用Eclipse和PyDev进行Django项目,并且可以正常工作...
一些要检查的东西:
是否有2个不同的过程?即:如果您在设置和视图中import os;print(os.getpid())
,是否是相同的pid? (我怀疑您是在看到进行自动重新加载的主进程的日志,而不是在实际执行代码的辅助进程上的日志)。