/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: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
import sys
18
20
import threading
19
21
 
 
22
from .sixish import (
 
23
    reraise,
 
24
)
 
25
 
20
26
 
21
27
class CatchingExceptionThread(threading.Thread):
22
28
    """A thread that keeps track of exceptions.
38
44
        super(CatchingExceptionThread, self).__init__(*args, **kwargs)
39
45
        self.set_sync_event(sync_event)
40
46
        self.exception = None
41
 
        self.ignored_exceptions = None  # see set_ignored_exceptions
 
47
        self.ignored_exceptions = None # see set_ignored_exceptions
42
48
        self.lock = threading.Lock()
43
49
 
44
50
    def set_sync_event(self, event):
79
85
        """
80
86
        cur = self.sync_event
81
87
        self.lock.acquire()
82
 
        try:  # Always release the lock
 
88
        try: # Always release the lock
83
89
            try:
84
90
                self.set_sync_event(new)
85
91
                # From now on, any exception will be synced with the new event
86
 
            except BaseException:
 
92
            except:
87
93
                # Unlucky, we couldn't set the new sync event, try restoring a
88
94
                # safe state
89
95
                self.set_sync_event(cur)
99
105
        """Declare which exceptions will be ignored.
100
106
 
101
107
        :param ignored: Can be either:
102
 
 
 
108
        
103
109
           - None: all exceptions will be raised,
104
110
           - an exception class: the instances of this class will be ignored,
105
111
           - a tuple of exception classes: the instances of any class of the
120
126
        try:
121
127
            try:
122
128
                super(CatchingExceptionThread, self).run()
123
 
            except BaseException:
 
129
            except:
124
130
                self.exception = sys.exc_info()
125
131
        finally:
126
132
            # Make sure the calling thread is released
127
133
            self.sync_event.set()
128
134
 
 
135
 
129
136
    def join(self, timeout=None):
130
137
        """Overrides Thread.join to raise any exception caught.
131
138
 
135
142
        super(CatchingExceptionThread, self).join(timeout)
136
143
        if self.exception is not None:
137
144
            exc_class, exc_value, exc_tb = self.exception
138
 
            self.exception = None  # The exception should be raised only once
 
145
            self.exception = None # The exception should be raised only once
139
146
            if (self.ignored_exceptions is None
140
 
                    or not self.ignored_exceptions(exc_value)):
 
147
                or not self.ignored_exceptions(exc_value)):
141
148
                # Raise non ignored exceptions
142
 
                raise exc_value
 
149
                reraise(exc_class, exc_value, exc_tb)
143
150
 
144
151
    def pending_exception(self):
145
152
        """Raise the caught exception.