/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/cethread.py

  • Committer: Jelmer Vernooij
  • Date: 2019-05-29 03:22:34 UTC
  • mfrom: (7303 work)
  • mto: This revision was merged to the branch mainline in revision 7306.
  • Revision ID: jelmer@jelmer.uk-20190529032234-mt3fuws8gq03tapi
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        super(CatchingExceptionThread, self).__init__(*args, **kwargs)
45
45
        self.set_sync_event(sync_event)
46
46
        self.exception = None
47
 
        self.ignored_exceptions = None # see set_ignored_exceptions
 
47
        self.ignored_exceptions = None  # see set_ignored_exceptions
48
48
        self.lock = threading.Lock()
49
49
 
50
50
    def set_sync_event(self, event):
85
85
        """
86
86
        cur = self.sync_event
87
87
        self.lock.acquire()
88
 
        try: # Always release the lock
 
88
        try:  # Always release the lock
89
89
            try:
90
90
                self.set_sync_event(new)
91
91
                # From now on, any exception will be synced with the new event
92
 
            except:
 
92
            except BaseException:
93
93
                # Unlucky, we couldn't set the new sync event, try restoring a
94
94
                # safe state
95
95
                self.set_sync_event(cur)
105
105
        """Declare which exceptions will be ignored.
106
106
 
107
107
        :param ignored: Can be either:
108
 
        
 
108
 
109
109
           - None: all exceptions will be raised,
110
110
           - an exception class: the instances of this class will be ignored,
111
111
           - a tuple of exception classes: the instances of any class of the
126
126
        try:
127
127
            try:
128
128
                super(CatchingExceptionThread, self).run()
129
 
            except:
 
129
            except BaseException:
130
130
                self.exception = sys.exc_info()
131
131
        finally:
132
132
            # Make sure the calling thread is released
133
133
            self.sync_event.set()
134
134
 
135
 
 
136
135
    def join(self, timeout=None):
137
136
        """Overrides Thread.join to raise any exception caught.
138
137
 
142
141
        super(CatchingExceptionThread, self).join(timeout)
143
142
        if self.exception is not None:
144
143
            exc_class, exc_value, exc_tb = self.exception
145
 
            self.exception = None # The exception should be raised only once
 
144
            self.exception = None  # The exception should be raised only once
146
145
            if (self.ignored_exceptions is None
147
 
                or not self.ignored_exceptions(exc_value)):
 
146
                    or not self.ignored_exceptions(exc_value)):
148
147
                # Raise non ignored exceptions
149
148
                reraise(exc_class, exc_value, exc_tb)
150
149