I’m going to make this short and sweet.
Scenario: You’re developing directly on Amazon ec2 without a local test environment. You edit Python code in WingIDE and rsync it over when it’s time to test.
Problem: Lack of interactive debugging.
Solution: ssh tunneling combined with WingIDE’s TCP-based remote debugging.
First, you need to install WingIDE on the ec2 instance. This isn’t as bad as it sounds — there are no X11 or GTK+ requirements for this purpose. Once it’s installed, put
wingdbstub.py someplace where you can import it. Inside
wingdbstub.py file, set
kExitOnFailure to 1 so that we know whether the debugger is attaching correctly. Try importing the file, and you should get this:
>>> import wingdbstub Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/mnt/py/wingdbstub.py", line 242, in <module> raise ValueError('Not connected') ValueError: Not connected
So now we know that if we don’t get this error, it’s connecting fine.
Next, you need to be sure what any files you want to debug are identical on both your desktop and the ec2 instance. They also either need to be in the same place on both machines, or you need to follow Wingware’s instructions on mapping the locations of remote and local files.
Once you’re sure the local and remote files are in parity and WingIDE will know where to look for them, do the tunneling. Using Wing’s default ports, here’s what your ssh command will look like:
ssh -L 50015:localhost:50015 -R 50005:localhost:50005 <user@hostname>
50015 is the port that wingdbstub.py will answer when the IDE attempts to connect and 50005 is the port the IDE will keep open for when wingdbstub.py tries to connect. Make sense? You can also forward extra ports if it’s handy. Say for example that your application listens on port 8080 and you want to access that in a web browser locally:
ssh -L 8080:localhost:8080 -L 50015:localhost:50015 -R 50005:localhost:50005 <user@hostname>
Fire up WingIDE, let your application catch an exception, and that’s about it. You’re good to go.
All of this is covered (more or less) in the WingIDE docs, except the ssh part. But the awesomeness factor of interactively debugging code somewhere in Amazon’s data center inspired me to post this little recipe. Enjoy.