How to manually close connection in BaseHTTPServer?
Posted
by
user1657188
on Stack Overflow
See other posts from Stack Overflow
or by user1657188
Published on 2012-09-09T15:35:41Z
Indexed on
2012/09/09
15:38 UTC
Read the original article
Hit count: 128
I have a script that sends a request to an HTTP server.
HTTP server script (snippet):
...
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(sa):
pdict = cgi.parse_header(sa.headers.getheader('referer'))
q = pdict[0]
q = urllib.unquote(q)
if q == "enternetixplorer" # basically just ignore this, doesn't have to do with the question
sa.wfile.write("blah blah blah")
# now restart server
httpd.server_close()
python = sys.executable
os.execl(python, python, * sys.argv)
...
The "blah blah blah" is sent back, but the connection does not seem to close, and my script is waiting forever until I abort the server. (My thought is BaseHTTPServer automatically closes connection when the last part in "do_GET()" is computed, but I prevent this by restarting the script.)
If I'm right, how do I close the connection? If not, what else might be the problem?
Edit: The server script HAS to restart the entire program.
© Stack Overflow or respective owner