/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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
 
 
19
17
import sys
20
18
import threading
21
19
 
40
38
        super(CatchingExceptionThread, self).__init__(*args, **kwargs)
41
39
        self.set_sync_event(sync_event)
42
40
        self.exception = None
43
 
        self.ignored_exceptions = None # see set_ignored_exceptions
 
41
        self.ignored_exceptions = None  # see set_ignored_exceptions
44
42
        self.lock = threading.Lock()
45
43
 
46
 
    # compatibility thunk for python-2.4 and python-2.5...
47
 
    if sys.version_info < (2, 6):
48
 
        name = property(threading.Thread.getName, threading.Thread.setName)
49
 
 
50
44
    def set_sync_event(self, event):
51
45
        """Set the ``sync_event`` event used to synchronize exception catching.
52
46
 
85
79
        """
86
80
        cur = self.sync_event
87
81
        self.lock.acquire()
88
 
        try: # Always release the lock
 
82
        try:  # Always release the lock
89
83
            try:
90
84
                self.set_sync_event(new)
91
85
                # From now on, any exception will be synced with the new event
92
 
            except:
 
86
            except BaseException:
93
87
                # Unlucky, we couldn't set the new sync event, try restoring a
94
88
                # safe state
95
89
                self.set_sync_event(cur)
105
99
        """Declare which exceptions will be ignored.
106
100
 
107
101
        :param ignored: Can be either:
108
 
        
 
102
 
109
103
           - None: all exceptions will be raised,
110
104
           - an exception class: the instances of this class will be ignored,
111
105
           - a tuple of exception classes: the instances of any class of the
126
120
        try:
127
121
            try:
128
122
                super(CatchingExceptionThread, self).run()
129
 
            except:
 
123
            except BaseException:
130
124
                self.exception = sys.exc_info()
131
125
        finally:
132
126
            # Make sure the calling thread is released
133
127
            self.sync_event.set()
134
128
 
135
 
 
136
129
    def join(self, timeout=None):
137
130
        """Overrides Thread.join to raise any exception caught.
138
131
 
142
135
        super(CatchingExceptionThread, self).join(timeout)
143
136
        if self.exception is not None:
144
137
            exc_class, exc_value, exc_tb = self.exception
145
 
            self.exception = None # The exception should be raised only once
 
138
            self.exception = None  # The exception should be raised only once
146
139
            if (self.ignored_exceptions is None
147
 
                or not self.ignored_exceptions(exc_value)):
 
140
                    or not self.ignored_exceptions(exc_value)):
148
141
                # Raise non ignored exceptions
149
 
                raise exc_class, exc_value, exc_tb
 
142
                raise exc_value
150
143
 
151
144
    def pending_exception(self):
152
145
        """Raise the caught exception.