def METHOD_NAME(tasks):
    """ this callback is invoked on all task state changes """
    # The approach to task state callbacks is the same as the one to
    # pilot state callbacks. Only difference is that task state
    # callbacks are invoked by the task manager on changes of task
    # states.
    #
    # The example below does not really create any Task object, we only
    # include the callback here for documentation on the approaches to error
    # handling.
    #
    # Note that other error handling semantics are available, depending on your
    # application requirements. For example, upon tasks failure, the
    # application could spawn replacement tasks, or spawn a pilot on a
    # different resource which might be better equipped to handle the task
    # payload.
    for task in tasks:
        print('  task %s: %s' % (task.uid, task.state))
        if task.state == rp.FAILED:
            print('                  : %s' % task.stderr)