当前位置: 首页>>代码示例>>Python>>正文


Python HTTPServer.server_close方法代码示例

本文整理汇总了Python中six.moves.BaseHTTPServer.HTTPServer.server_close方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPServer.server_close方法的具体用法?Python HTTPServer.server_close怎么用?Python HTTPServer.server_close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.BaseHTTPServer.HTTPServer的用法示例。


在下文中一共展示了HTTPServer.server_close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: oauth_server

# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import server_close [as 别名]
def oauth_server():
    # Start the OAuth server on a random port in the background
    server = HTTPServer(('', 0), OAuthHandler)
    server.url = 'http://{0}:{1}/'.format(*server.server_address)
    thread = threading.Thread(target=server.serve_forever)
    thread.start()
    try:
        yield server
    finally:
        server.shutdown()
        thread.join()
        server.server_close()
开发者ID:5225225,项目名称:rtv,代码行数:14,代码来源:conftest.py

示例2: SimpleWebServer

# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import server_close [as 别名]
class SimpleWebServer(object):
    """A very basic web server."""
    def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT):
        self.stop_serving = False
        host = host
        port = port
        while True:
            try:
                self.server = HTTPServer(
                    (host, port), HtmlOnlyHandler)
                self.host = host
                self.port = port
                break
            except socket.error:
                log.debug("port %d is in use, trying to next one" % port)
                port += 1

        self.thread = threading.Thread(target=self._run_web_server)

    def _run_web_server(self):
        """Runs the server loop."""
        log.debug("web server started")
        while not self.stop_serving:
            self.server.handle_request()
        self.server.server_close()

    def start(self):
        """Starts the server."""
        self.thread.start()

    def stop(self):
        """Stops the server."""
        self.stop_serving = True
        try:
            # This is to force stop the server loop
            URLopener().open("http://%s:%d" % (self.host, self.port))
        except IOError:
            pass
        log.info("Shutting down the webserver")
        self.thread.join()

    def where_is(self, path):
        return "http://%s:%d/%s" % (self.host, self.port, path)
开发者ID:HuntJSparra,项目名称:bokeh,代码行数:45,代码来源:file_server.py


注:本文中的six.moves.BaseHTTPServer.HTTPServer.server_close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。