當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。