基础知识:
- 我有一个 Django 项目,它在本地和远程服务器上都可以正常运行。
我使用“远程调试”配置文件在本地启动 PyCharm,一切看起来很好。
Starting debug server at port 4000
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('<my local machines public ip addr>', port=4000, suspend=False)
Waiting for connection...
在远程服务器上,我在__init__.py
中放置了对pycharm-debug.egg
的适当调用(但我也尝试将其放置在代码的其他位置)。
我这样启动远程服务器:python manage.py runserver <远程域名>:8000
,在本地的PyCharm IDE/调试器中看到:
"Connected to pydev debugger (build 133.1347)"
之后,事情就只是停在那里了... 我没有得到任何有关执行进度的反馈,在 PyCharm IDE 中也无法 "开始/继续/运行" 任何东西。
在远程服务器上如果我按下<ctrl-c>
,我会看到:
File "/<path here>/pycharm-debug.egg/pydevd.py", line 1256, in settrace
File "/<path here>/pycharm-debug.egg/pydevd.py", line 1305, in _locked_settrace
我猜测所有连接都已正确连接,但我没有看到任何启动一切运行的方法。我已经设置了 "suspend=False",所以我本应该期望它会开始运行。当我尝试访问远程服务器上的页面时,我得到了 "not connected" 的提示,因此网页服务器显然还没有运行(如果 curl http://<remote server domain>:8000
,我会得到curl:(7) Failed connect to <remote server domain>:8000; Connection refused
)。在没有远程调试的情况下,在我的本地开发机器或远程服务器上运行都很好。
我做错了什么?:) 谢谢!
细节:
在承载要调试的代码/进程的远程服务器上的主要
__init__.py
中,我有:
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.append(BASE_DIR + '/pycharm-debug.egg')
import pydevd
pydevd.settrace('<my local machines public ip addr>', port=4000, suspend=False)
本地的PyCharm IDE 显示如下:
Starting debug server at port 4000
Use the following code to connect to the debugger:
import pydevd
pydevd.settrace('localhost', port=4000, suspend=False) (tried with <public ip addr> for this, too.
Waiting for connection...
---- and then, after I start the remote server process: ----
Connected to pydev debugger (build 133.1347)
其他说明:
- 我已经在远程服务器上尝试过使用和不使用virtualenv,均无法运行。
- 我正在普通的 Comcast 电缆调制解调器路由器后面运行本地的 PyCharm IDE,并打开了端口转发以将端口4000转发到我的本地机器(并在我从远程服务器对其进行wget时测试成功地将一个节点服务器附加到端口4000)。
我不知道如何“推动”任何东西来使它们运行,并让我开始调试。
感谢您的帮助。
suspend=False
吗?这明确表示不设置断点(请检查我的答案)。 - vlad-ardelean