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


Python server.shutdown方法代码示例

本文整理汇总了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() 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:10,代码来源:advancedhttpserver.py

示例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() 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:8,代码来源:advancedhttpserver.py

示例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 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:33,代码来源:advancedhttpserver.py

示例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 
开发者ID:zeroSteiner,项目名称:AdvancedHTTPServer,代码行数:10,代码来源:advancedhttpserver.py

示例5: shutdown

# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def shutdown(self):
        http.server.HTTPServer.shutdown(self) 
开发者ID:keylime,项目名称:keylime,代码行数:4,代码来源:registrar_common.py

示例6: do_shutdown

# 需要导入模块: from http import server [as 别名]
# 或者: from http.server import shutdown [as 别名]
def do_shutdown(servers):
    for server in servers:
        server.shutdown() 
开发者ID:keylime,项目名称:keylime,代码行数:5,代码来源:registrar_common.py

示例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 
开发者ID:demisto,项目名称:content,代码行数:40,代码来源:rasterize_test.py


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