很长一段时间以来,我的 Windows 10 机器上都出现了这个奇怪的问题。尝试在 PyCharm 上调试(有时甚至不调试)启动 Django 服务器时,出现此错误:
...
pydev debugger: process 10532 is connecting
Connected to pydev debugger (build 163.8233.8)
Process finished with exit code -1073741819 (0xC0000005)
这是没有调试的样子:
"C:\Program Files (x86)\PyCharm\bin\runnerw.exe" D:\project\env\Scripts\python.exe D:/project/manage.py runserver 80
Process finished with exit code -1073741819 (0xC0000005)
最奇怪的是,如果我重新运行,有时(大约 4-6 次重新运行中有 1 次成功)它会成功启动。如果没有 PyCharm,我也无法重现这个问题。
规范:Windows 10 Pro、Pycharm(这发生在 5.x 到 2016.3 版本)x86 和 x64 版本、Python 3.5x、Django 1.8-1.10.x。
知道为什么会发生这种情况或如何获取有关崩溃的更多详细信息吗?
编辑 这是事件查看器报告的错误:
Faulting application name: python.exe, version: 3.5.1150.1013, time stamp: 0x566391f0
Faulting module name: ucrtbase.dll, version: 10.0.14393.0, time stamp: 0x57898db2
Exception code: 0xc0000005
Fault offset: 0x000b6d95
Faulting process ID: 0x1b30
Faulting application start time: 0x01d251286ca8ada3
Faulting application path: D:\project\env\Scripts\python.exe
Faulting module path: C:\WINDOWS\System32\ucrtbase.dll
Report ID: b23376d6-cf66-4d83-8781-cd22311e0f9e
Faulting package full name:
Faulting package-relative application ID:
EDIT 2 我已经缩小了问题的范围。该错误似乎源自 autoreload.py
中的 restart_with_reloader
在此语句之后:
def restart_with_reloader():
while True:
args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions] + sys.argv
if sys.platform == "win32":
args = ['"%s"' % arg for arg in args]
new_environ = os.environ.copy()
new_environ["RUN_MAIN"] = 'true'
# this line crashes the whole script
# I guess the problem arises in native code
exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
# debugger disconnects here
if exit_code != 3:
return exit_code
也许 Python 社区的人已经看到了类似的东西?
最佳答案
tl;dr 解决方案
在 Run/Debug Configurations
对话框中的 Environment variables
添加这对:
=C:
c:\''
我已经向 JetBrains YouTrack 提交了一张票,这实际上是 Windows 如何处理命令行环境变量的问题。您可以在此处找到该问题的解决方法:https://youtrack.jetbrains.com/issue/PY-17069
摘自 JetBrains 开发评论:
Guys, I just found a bug in Windows and Microsoft CRT:) Try to add following env variable to environment variables in run config =C: = c:`` Yes, =C: is NAME and c:`` is value.
关于python - PyCharm Django 项目调试运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034361/