def exec_on_disconnect(self, code, any_connection=False):
        """Add code that will be executed when client has disconnected.
        """
        if not any_connection:
            conn_id = _g_executing_pythonshare_conn_id
        else:
            conn_id = None
        self._on_disconnect.append((conn_id, code))