简体   繁体   中英

Attaching CGI python script to PyCharm debugger?

I'm using Community Edition PyCharm 4.5.1 and I'm developing CGI python scripts. My needs are to start the debugger and attach the script (then break to the first breakpoint) once 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'm perfectly able to debug a Python script I just start normally. But now the problem is that it is the HTTP server that starts the script, neither me (from command line) nor the debugger itself.

Any idea? Thanks!

AFAIK, you just put into your script

import cgitb    
cgitb.enable()  
print "Content-type: text/html\n\n"

and it's being debugged by itself.

I have meet the same problem as yours when i use pycharm on CentOS, but i found pycharm can attach to cgi script automaticly on windows , so i try to follow the source code of CGIRequestHandler, I found there is a difference in CGIRequestHandler.run_cgi() function, it will use fork on linux, and subprocess on windows, so i guess may be these two different ways of creating child process leading to different result. so i try the following code, force it subprocess on linux, and it works!

    CGIHTTPRequestHandler.have_fork = 0
    httpd = HTTPServer(('', port), CGIHTTPRequestHandler)        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM