我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用http.server.server_close()。
def main(): global server server = http.server.HTTPServer((host,port),HTTPRecquestHandler) print(time.asctime(),'Server started on port',port) print('....') print('ctrl-c to quit server.') try: server.serve_forever() if(close==True): raise #server.server_close() except KeyboardInterrupt: server.server_close() print(time.asctime(),"Server Stopped") except: server.server_close() print(time.asctime(),"Server Stopped")
def main(cls, RequestHandlerClass, port=80): """Start server with handler on given port. This static method provides an easy way to start, run, and exit a HttpServer instance. The server will be executed if possible, and the computer's web browser will be directed to the address.""" try: server = cls(('', port), RequestHandlerClass) active = True except socket.error: active = False else: addr, port = server.socket.getsockname() print('Serving HTTP on', addr, 'port', port, '...') finally: port = '' if port == 80 else ':' + str(port) addr = 'http://localhost' + port + '/' webbrowser.open(addr) if active: try: server.serve_forever() except KeyboardInterrupt: print('Keyboard interrupt received: EXITING') finally: server.server_close()
def http_server(self, lhost, lport): print_warning("Setting up HTTP server") server = HttpServer((lhost, int(lport)), HttpRequestHandler) server.serve_forever(self.revshell) server.server_close()