clockblocks.utilities.fork

clockblocks.utilities.fork(forked_function: Callable, args: Sequence = (), kwargs: dict = None, name: str = None, initial_rate: float = None, initial_tempo: float = None, initial_beat_length: float = None, when: float | 'moment.ResolvableMoment' = None, done_callback: Callable = None) → Clock[source]

Run forked_function on a new child clock of the currently active clock, so it proceeds in parallel while staying coordinated under the same musical time. See fork(); raises NoActiveClockError if there is no active clock.

Parameters:
  • forked_function – the function to run on the child clock. Note that, unlike the original clockblocks, the child clock is not injected as an argument — call current_clock() from inside the function if you need a reference to it.

  • args – positional arguments passed to forked_function.

  • kwargs – keyword arguments passed to forked_function.

  • name – optional name for the child clock, useful for debugging.

  • initial_rate – the child’s starting rate in beats per second. Give at most one of initial_rate/initial_tempo/initial_beat_length; if none is given the child starts at rate 1.

  • initial_tempo – the child’s starting tempo in beats per minute.

  • initial_beat_length – the child’s starting beat length in seconds per beat.

  • when – when to start the fork. None (the default) starts it immediately; otherwise pass a Moment (e.g. Moment.after_beats(4) or Moment.at_time(10)) or a MetricPhaseTarget. Unlike wait(), a bare number is rejected here, since we don’t know from context whether it’s beats/time, relative/absolute.

  • done_callback – an optional function called when the forked function finishes.

Returns:

the newly created child Clock.