ct.util

Utility functions for camtools.

ct.util.mt_loop(func, inputs, **kwargs)[source]

Applies a function to each item in the given list in parallel using multi-threading.

Parameters:
  • func (Callable[[Any], Any]) – Callable function that accepts a single argument.

  • inputs (Iterable[Any]) – Iterable of inputs to process with the function.

  • **kwargs – Additional keyword arguments to pass to func.

Returns:

A list of results from applying func to each item in inputs.

Return type:

list

ct.util.mp_loop(func, inputs, **kwargs)[source]

Applies a function to each item in the given list in parallel using multi-processing.

Parameters:
  • func (Callable[[Any], Any]) – Callable function that accepts a single argument.

  • inputs (Iterable[Any]) – Iterable of inputs to process with the function.

  • **kwargs – Additional keyword arguments to pass to func.

Returns:

A list of results from applying func to each item in inputs.

Return type:

list

ct.util.query_yes_no(question, default=None)[source]

Ask a yes/no question via raw_input() and return their answer.

Parameters:
  • question (str) – The question that is presented to the user.

  • default (bool | None) – Presumed answer if the user just hits <Enter>. - True: The answer is assumed to be yes. - False: The answer is assumed to be no. - None: The answer is required from the user.

Returns:

True for “yes” or False for “no”.

Return type:

bool

Examples

if query_yes_no("Continue?", default=True):
    print("Proceeding.")
else:
    print("Aborted.")

if not query_yes_no("Continue?", default=True):
    print("Aborted.")
    return  # Or exit(0)
print("Proceeding.")