本文整理匯總了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()
示例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)