When the flow is in spectator_mode, we have to disable signals, pickle dump and possible callbacks
        A spectator can still operate on the flow but the new status of the flow won't be saved in
        the pickle file. Usually the flow is in spectator mode when we are already running it via
        the scheduler or other means and we should not interfere with its evolution.
        This is the reason why signals and callbacks must be disabled.
        Unfortunately preventing client-code from calling methods with side-effects when
        the flow is in spectator mode is not easy (e.g. flow.cancel will cancel the tasks submitted to the
        queue and the flow used by the scheduler won't see this change!

def set_spectator_mode(self, mode=True):
        """
        When the flow is in spectator_mode, we have to disable signals, pickle dump and possible callbacks
        A spectator can still operate on the flow but the new status of the flow won't be saved in
        the pickle file. Usually the flow is in spectator mode when we are already running it via
        the scheduler or other means and we should not interfere with its evolution.
        This is the reason why signals and callbacks must be disabled.
        Unfortunately preventing client-code from calling methods with side-effects when
        the flow is in spectator mode is not easy (e.g. flow.cancel will cancel the tasks submitted to the
        queue and the flow used by the scheduler won't see this change!
        """
        # Set the flags of all the nodes in the flow.
        mode = bool(mode)
        self.in_spectator_mode = mode
        for node in self.iflat_nodes():
            node.in_spectator_mode = mode

        # connect/disconnect signals depending on mode.
        if not mode:
            self.connect_signals()
        else:
            self.disconnect_signals()