def priority(prio=0):
    """A decorator to set priority on handler functions and handlers.

    Default priority is 0. Handlers with higher priority are invoked first.
    Recommended priority values are 1 and -1. In most cases more than 3 priority
    classes are not required.
    """
    def wrap(func):
        func.__priority = prio
        return func
    return wrap