/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 bzrlib/cethread.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-22 14:12:22 UTC
  • mfrom: (5809 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110422141222-nx2j0hbkihcb8j16
Merge newer bzr.dev and resolve conflicts.
Try to write some documentation about how the _dirblock_state works.
Fix up the tests so that they pass again.

Show diffs side-by-side

added added

removed removed

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