Stopping a *HTTPServer

David LeBlanc whisper at oz.nospamnet
Fri May 25 12:17:58 EDT 2001


In article <67abb823.0105250734.24705e9d at posting.google.com>, 
mt_horeb at yahoo.com says...
> Here's the situation - I'm building a quick-and-dirty application that
> serves CGI and HTML via the CGIHTTPServer module.  So far, so good. 
> The only issue that I am having is that I cannot figure out how to
> stop the server once I've started it with serve_forever().
> 
> I've taken a look at some newsgroup posts and Web sites (incl.
> http://www.python.org), but I cannot seem to locate an answer!  I
> would certainly appreciate anything that is more 'elegant' than simply
> using Ctrl-C!
> 
> Here is the (very basic) code to create and start the server:
> 
> import CGIHTTPServer, BaseHTTPServer
> class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
> 	cgi_directories = ["/cgi-bin"]
> 
> def startServer():
> 	PORT = 8000
> 	httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
> 	httpd.serve_forever()
> 
> 
> Thanks!
> 
> Sloth
> 
What's your objection to Ctrl-C? If it's the abrupt nature of the 
termination, just trap the Ctrl-C and do cleanup before exiting.



More information about the Python-list mailing list