Attaching a CGI python script to the PyCharm debugger?
I am using Community Edition PyCharm 4.5.1 and I am developing python CGI scripts. I need to start the debugger and attach the script (then break until the first breakpoint) as soon as it is called by my HTTP client.
I don't know if I can, I hope. Everything works fine, from the Python server to the HTML / JavaScript code that calls my CGI script. Also, I am great at debugging Python script, I just start out fine. But now the problem is that the HTTP server runs the script, neither me (from the command line) nor the debugger itself.
Any idea? Thank!
source to share
I have the same problem as you when I use pycharm on CentOS, but I found that pycharm can attach to the cgi script automatically on windows , so I try to follow the CGIRequestHandler source code.I found there is a difference in function CGIRequestHandler.run_cgi (), it will fork on linux and subprocess on Windows, so I think it could be two different ways of creating a child process, leading to different results. so i try the following code, force its subprocess on linux and it works!
CGIHTTPRequestHandler.have_fork = 0
httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
source to share