BaseHTTPServer.HTTPServer 如何停止

BaseHTTPServer.HTTPServer是python中一个很好用的够简单的http服务器的库,但是它的stop_server方法是空的,所以开始用的时候老是不知道怎么才能关掉它,了解后终于找到了方法,备忘一下:

   
class HttpServer(BaseHTTPServer.HTTPServer):
        
    def serve_forever(self):
        self.stopped = False                    
        """Handle one request at a time until doomsday."""
        while not self.stopped:
            self.handle_request()
    def (self):
        self.stopped = True
        conn = httplib.HTTPConnection("localhost:%d" % 8080)
        conn.request("QUIT", "/")

 

class InfocServerHandler(SimpleHTTPRequestHandler):   
    def do_GET(self):
        scm, netloc, path, params, query, fragment = urlparse.urlparse(self.path, 'http')   
        self.wfile.write('HTTP/1.1 200 OK\r\n')
        self.send_header('Content-Length',len(dat))
        self.send_header('Cache-Control','max-age=1')
        self.send_header('Content-Type','application/x-shockwave-flash')
        self.end_headers()
        self.wfile.write(dat)
  
   

posted @ 2010-06-11 21:05  Gang.Wang  阅读(3091)  评论(0编辑  收藏  举报