def on_close(self): # Close session if websocket connection was closed if self.session is not None: # Stats self.server.stats.on_conn_closed() session = self.session self._detach() session.close()