def connection_lost(self, reason=None): """Called when the connection is lost""" if self.protocol_mode in ("login", "play"): self.factory.players.discard(self) Protocol.connection_lost(self, reason)