本文整理汇总了Python中http.server.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python server.shutdown方法的具体用法?Python server.shutdown怎么用?Python server.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.server
的用法示例。
在下文中一共展示了server.shutdown方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: finish_request
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def finish_request(self, request, client_address):
try:
super(ServerNonThreaded, self).finish_request(request, client_address)
except IOError:
self.logger.warning('IOError encountered in finish_request')
except KeyboardInterrupt:
self.logger.warning('KeyboardInterrupt encountered in finish_request')
self.shutdown()
示例2: shutdown
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def shutdown(self, *args, **kwargs):
try:
self.socket.shutdown(socket.SHUT_RDWR)
except socket.error:
pass
self.socket.close()
示例3: serve_forever
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def serve_forever(self, fork=False):
"""
Start handling requests. This method must be called and does not
return unless the :py:meth:`.shutdown` method is called from
another thread.
:param bool fork: Whether to fork or not before serving content.
:return: The child processes PID if *fork* is set to True.
:rtype: int
"""
if fork:
if not hasattr(os, 'fork'):
raise OSError('os.fork is not available')
child_pid = os.fork()
if child_pid != 0:
self.logger.info('forked child process: ' + str(child_pid))
return child_pid
self.__server_thread = threading.current_thread()
self.__wakeup_fd = WakeupFd()
self.__is_shutdown.clear()
self.__should_stop.clear()
self.__is_running.set()
while not self.__should_stop.is_set():
try:
self._serve_ready()
except socket.error:
self.logger.warning('encountered socket error, stopping server')
self.__should_stop.set()
self.__is_shutdown.set()
self.__is_running.clear()
return 0
示例4: tearDown
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def tearDown(self):
if not self.shutdown_requested:
self.assertTrue(self.server_thread.is_alive())
self.http_connection.close()
self.server.shutdown()
self.server_thread.join(10.0)
self.assertFalse(self.server_thread.is_alive())
del self.server
示例5: shutdown
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def shutdown(self):
http.server.HTTPServer.shutdown(self)
示例6: do_shutdown
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def do_shutdown(servers):
for server in servers:
server.shutdown()
示例7: http_wait_server
# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def http_wait_server():
# Simple http handler which waits 10 seconds before responding
class WaitHanlder(http.server.BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
def do_GET(self):
time.sleep(10)
try:
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes("<html><head><title>Test wait handler</title></head>"
"<body><p>Test Wait</p></body></html>", 'utf-8'))
self.flush_headers()
except BrokenPipeError: # ignore broken pipe as socket might have been closed
pass
# disable logging
def log_message(self, format, *args):
pass
with http.server.ThreadingHTTPServer(('', 10888), WaitHanlder) as server:
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
yield
server.shutdown()
server_thread.join()
# Some web servers can block the connection after the http is sent
# In this case chromium will hang. An example for this is:
# curl -v -H 'user-agent: HeadlessChrome' --max-time 10 "http://www.grainger.com/" # disable-secrets-detection
# This tests access a server which waits for 10 seconds and makes sure we timeout