def run_application(self): path = self.environ.get('PATH_INFO') content_type = self.server.data_handlers.get(path) if content_type is not None: self.serve_file(basename(path), content_type) return websocket_mode = False if WebSocket.is_socket(self.environ): self.status = 'websocket' self.log_request() self.environ['websocket'] = WebSocket(self.environ, self.socket, self.rfile) websocket_mode = True try: self.result = self.application(self.environ, self.start_response) if self.result is not None: self.process_result() except: websocket = self.environ.get('websocket') if websocket is not None: websocket.close() raise finally: if websocket_mode: # we own the socket now, make sure pywsgi does not try to read from it: self.socket = None