<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def priority(self,priority):
 """Set the priority for all threads in this group. If setting priority fails on any thread, the priority of all threads is restored to its previous value. """

        with self.__lock:
            old_priorities = {}
            try:
                for thread in self.__threads:
                    old_priorities[thread] = thread.priority
                    thread.priority = priority
            except Exception:
                for (thread,old_priority) in old_priorities.iteritems():
                    try:
                        thread.priority = old_priority
                    except Exception:
                        pass
                raise
            else:
                self.__priority = priority