Python http.server 模块,serve_forever() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用http.server.serve_forever()

项目:Server    作者:astinaam    | 项目源码 | 文件源码
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")
项目:code    作者:ActiveState    | 项目源码 | 文件源码
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()
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def serve_forever(self, poll_interval=0.5):
        """Handle all incoming client requests forever.

        This method has been overridden so that SystemExit exceptions
        raised in the RequestHandlerClass can be re-raised after being
        caught in the handle_error method above. This allows servlet
        code to terminate server execution if so desired or required."""
        super().serve_forever(poll_interval)
        if self._BaseServer__serving is None:
            raise self.__exit
项目:rpwd    作者:ivytin    | 项目源码 | 文件源码
def serve_forever(self, content):
        self.stop = False
        self.content = content
        while not self.stop:
            self.handle_request()
项目:rpwd    作者:ivytin    | 项目源码 | 文件源码
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()
项目:Cisco-Showroom-RoomControl    作者:gbraux    | 项目源码 | 文件源码
def startThread():


    server = ThreadedHTTPServer(('0.0.0.0', 1412), MyRequestHandler)
    print('Starting server, use <Ctrl-C> to stop')

    thread = threading.Thread(target = server.serve_forever)
    thread.deamon = False
    thread.start()

    print("--- WEB Server started (1235) ---")
    return server
项目:SET_Vault9    作者:Ninja-Tw1sT    | 项目源码 | 文件源码
def serve_forever(self):
        """Handle one request at a time until stopped."""
        self.stop = False
        while not self.stop:
            self.handle_request()

# stop the http server
项目:SET_Vault9    作者:Ninja-Tw1sT    | 项目源码 | 文件源码
def start_server(web_port, path):
    os.chdir(path)
    web_port = int(web_port)
    server = StoppableHttpServer(('', web_port), StoppableHttpRequestHandler)
    server.serve_forever()