问题
Using WingIDE to debug a web application, I have set a breakpoint in some Python code which runs when a web-form is submitted. Just before the breakpoint I have inserted 'import wingdbstub' to activate remote deubgging. However, execution does not stop at the breakpoint. I know the code is running because if I insert 'raise exception(sys.modules)' just before the breakpoint, execution stops and a traceback appears in my browser, showing wingdbstub is loaded.
If I hover over the bug icon in the status-bar, a dialog says "No debug process / listening for connections on TCP/IP 50005. Allowed hosts 127.0.0.1". I know I have 'lost' debug mode when a) the bug icon changes from green to white, and b) the debugging toolbar buttons (step into, over, out, etc.) disappear.
I tried deleting compiled .pyc files so that they recompile when the module next runs, but the problem remains.
How can I check if Wing is listening on the correct port? The strange thing is that remote-debugging has worked sometimes, but most of the time it doesn't.
Any help would be appreciated. For the record, I am using Python 3.1, CherryPy 3.20 and WingIDE Personal 3.2.11.
Alan
回答1:
Under Windows, I've experienced the same behavior you mention, i.e., remote debugging sometimes works, but often 'gets stuck'. I've found a few things helpful in resolving this situation:
- Make sure your firewall isn't blocking traffic to/from the ports being used by WingIDE and the process being debugged. (In my case, I had to unblock both wing.exe and the program I was attempting to debug in Windows Firewall.)
- Make sure you haven't accumulated any zombie python processes after failed debug sessions. These can hold open a connection to the IDE, making it impossible for a newly-spawned instance to connect. (Under Windows, you can use the
tasklist
command to check for running python instances, andnetstat -anp tcp
will show any sockets stuck in the TIME_WAIT state.) - Insert a
time.sleep(10)
call immediately after yourimport wingdbstub
statement. Start the program from a console, make sure it connects in the IDE (debug icon will turn green), then hit the 'Pause' button in the IDE, followed by 'Step Out'. (I can't begin to explain why, but this appeared to right the ship for me a couple of times after the debug connection had gone wonky.)
The above advice probably applies to Linux as well, but I've only experienced this problem under Windows so far...
来源:https://stackoverflow.com/questions/4063482/remote-debugging-with-wingide