Problem exiting application in Windows Console.

Ant antroy at
Wed Nov 8 13:10:54 CET 2006

Hi all,

I'm putting together a simple help module for my applications, using
html files stored in the application directory somewhere. Basically it
sets up a basic web server, and then uses the webbrowser module to
display it in the users browser. I have it set up to call sys.exit(0)
if the url quit.html is called, but for some reason (on Windows XP via
the cmd.exe shell) python won't let me have the console back. I get the
System Exit stack trace OK:

Exception happened during processing of request from ('',
Traceback (most recent call last):
  File "C:\Documents and Settings\aroy\My Do...
SystemExit: 0

However, at this point instead of getting back to a command prompt, I
get an unresponsive console. Hitting CTRL-Break gets me the command
prompt back, but I would have expected to get back the command prompt
as soon as the sys.exit(0) had completed.

Here's the code:

import webbrowser, os, sys
from threading import Thread
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

class HelpHTTPRequestHandler(SimpleHTTPRequestHandler):
    def do_GET(self):
        print "PATH: ", self.path
        if self.path.endswith("quit.html"):
            print "Exiting..."
            return SimpleHTTPRequestHandler.do_GET(self)

def help(base_dir, server_class=HTTPServer,
    server_address = ('', 8000)
    httpd = server_class(server_address, handler_class)
    server_thread = Thread(target=httpd.serve_forever)

    print "Hit CTRL-Break or CTRL-C to exit server"

def main():
    current_dir = os.path.split(sys.argv[0])[0]

if __name__ == "__main__":

More information about the Python-list mailing list