2

Visual Studio has great python support via the Python Tools for Visual Studio: http://pytools.codeplex.com/

Debugging python code in Visual Studio works as expected. I set up a lighttpd server on my local Windows machine, and I have python scripts running as cgi scripts. I would like to be able to debug these in Visual Studio (running on the same PC) when running from lighttpd.

I am able to debug the cgi scripts using: http://winpdb.org But I would prefer Visual Studio.

According to this question: How to debug a remote python application with (Python Tools for) Visual Studio?

It is implied there is almost a way, but I don't see a specific way to set a breakpoint and have it debugged in VS.

2
  • If this is just on your local machine does Debug->Attach to Process work for you? In theory you can attach to the cgi process, set breakpoints, and start debugging. Commented Jun 8, 2012 at 3:02
  • Yes, Debug->Attach does work. I listed the steps in my answer. Commented Jun 8, 2012 at 10:42

1 Answer 1

4

Figured it out. This does work, and works pretty well, once you get the steps down.

  • Add a delay to the python source file like this:

    time.sleep(10)
    

    This is necessary if you are not using FastCGI, as the python process is probably going to start and finish long before you can attach to it. I assume this would be different with FastCGI, but I haven't reached that stage yet.

  • Set a breakpoint in your python file that is running in your lighttpd (or apache?) server. I tested lighttpd. Note: If you don't add the source file to a project in VS, and thus don't set a breakpoint, you can still debug, but you'll have to force an error in the file. I added a line 'debugger' which worked.
  • Load the page in a browser and allow the delay to be hit
  • In VS: Debug -> Attach to process -> pythonw.exe (complete this before the delay elapses)

I added a short macro to the Visual Studio IDE that automates the procedure of attaching to pythonw.exe. I'll share that if anyone is interested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.