~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Lib/threading.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
 
107
107
    def __repr__(self):
108
108
        owner = self.__owner
109
 
        return "<%s(%s, %d)>" % (
110
 
                self.__class__.__name__,
111
 
                owner and owner.name,
112
 
                self.__count)
 
109
        try:
 
110
            owner = _active[owner].name
 
111
        except KeyError:
 
112
            pass
 
113
        return "<%s owner=%r count=%d>" % (
 
114
                self.__class__.__name__, owner, self.__count)
113
115
 
114
116
    def acquire(self, blocking=1):
115
 
        me = current_thread()
116
 
        if self.__owner is me:
 
117
        me = _get_ident()
 
118
        if self.__owner == me:
117
119
            self.__count = self.__count + 1
118
120
            if __debug__:
119
121
                self._note("%s.acquire(%s): recursive success", self, blocking)
132
134
    __enter__ = acquire
133
135
 
134
136
    def release(self):
135
 
        if self.__owner is not current_thread():
136
 
            raise RuntimeError("cannot release un-aquired lock")
 
137
        if self.__owner != _get_ident():
 
138
            raise RuntimeError("cannot release un-acquired lock")
137
139
        self.__count = count = self.__count - 1
138
140
        if not count:
139
141
            self.__owner = None
168
170
        return (count, owner)
169
171
 
170
172
    def _is_owned(self):
171
 
        return self.__owner is current_thread()
 
173
        return self.__owner == _get_ident()
172
174
 
173
175
 
174
176
def Condition(*args, **kwargs):
227
229
 
228
230
    def wait(self, timeout=None):
229
231
        if not self._is_owned():
230
 
            raise RuntimeError("cannot wait on un-aquired lock")
 
232
            raise RuntimeError("cannot wait on un-acquired lock")
231
233
        waiter = _allocate_lock()
232
234
        waiter.acquire()
233
235
        self.__waiters.append(waiter)
269
271
 
270
272
    def notify(self, n=1):
271
273
        if not self._is_owned():
272
 
            raise RuntimeError("cannot notify on un-aquired lock")
 
274
            raise RuntimeError("cannot notify on un-acquired lock")
273
275
        __waiters = self.__waiters
274
276
        waiters = __waiters[:n]
275
277
        if not waiters:
468
470
        _active_limbo_lock.acquire()
469
471
        _limbo[self] = self
470
472
        _active_limbo_lock.release()
471
 
        _start_new_thread(self.__bootstrap, ())
 
473
        try:
 
474
            _start_new_thread(self.__bootstrap, ())
 
475
        except Exception:
 
476
            with _active_limbo_lock:
 
477
                del _limbo[self]
 
478
            raise
472
479
        self.__started.wait()
473
480
 
474
481
    def run(self):
815
822
 
816
823
active_count = activeCount
817
824
 
 
825
def _enumerate():
 
826
    # Same as enumerate(), but without the lock. Internal use only.
 
827
    return _active.values() + _limbo.values()
 
828
 
818
829
def enumerate():
819
830
    _active_limbo_lock.acquire()
820
831
    active = _active.values() + _limbo.values()