我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用gevent.pywsgi.WSGIHandler()。
def run_application(self): upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower() if upgrade_header: # Build and start the HTTP response self.environ['ws4py.socket'] = self.socket or self.environ['wsgi.input'].rfile._sock self.result = self.application(self.environ, self.start_response) or [] self.process_result() del self.environ['ws4py.socket'] self.socket = None self.rfile.close() ws = self.environ.pop('ws4py.websocket', None) if ws: ws_greenlet = self.server.pool.track(ws) # issue #170 # in gevent 1.1 socket will be closed once application returns # so let's wait for websocket handler to finish ws_greenlet.join() else: gevent.pywsgi.WSGIHandler.run_application(self)
def run_application(self): upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower() if upgrade_header: try: # Build and start the HTTP response self.environ['ws4py.socket'] = self.socket or self.environ['wsgi.input'].rfile._sock self.result = self.application(self.environ, self.start_response) or [] self.process_result() except: raise else: del self.environ['ws4py.socket'] self.socket = None self.rfile.close() ws = self.environ.pop('ws4py.websocket') if ws: self.server.pool.track(ws) else: gevent.pywsgi.WSGIHandler.run_application(self)