Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
threading._Condition Class Reference
Inheritance diagram for threading._Condition:
Inheritance graph
[legend]
Collaboration diagram for threading._Condition:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __enter__
def __exit__
def __repr__
def wait
def wait_for
def notify
def notify_all

Public Attributes

 acquire
 release
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 notifyAll = notify_all

Private Member Functions

def _release_save
def _acquire_restore
def _is_owned

Private Attributes

 _lock
 _release_save
 _acquire_restore
 _is_owned
 _waiters

Detailed Description

Definition at line 176 of file threading.py.


Constructor & Destructor Documentation

def threading._Condition.__init__ (   self,
  lock = None,
  verbose = None 
)

Definition at line 178 of file threading.py.

00178 
00179     def __init__(self, lock=None, verbose=None):
00180         _Verbose.__init__(self, verbose)
00181         if lock is None:
00182             lock = RLock()
00183         self._lock = lock
00184         # Export the lock's acquire() and release() methods
00185         self.acquire = lock.acquire
00186         self.release = lock.release
00187         # If the lock defines _release_save() and/or _acquire_restore(),
00188         # these override the default implementations (which just call
00189         # release() and acquire() on the lock).  Ditto for _is_owned().
00190         try:
00191             self._release_save = lock._release_save
00192         except AttributeError:
00193             pass
00194         try:
00195             self._acquire_restore = lock._acquire_restore
00196         except AttributeError:
00197             pass
00198         try:
00199             self._is_owned = lock._is_owned
00200         except AttributeError:
00201             pass
00202         self._waiters = []

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 203 of file threading.py.

00203 
00204     def __enter__(self):
00205         return self._lock.__enter__()

def threading._Condition.__exit__ (   self,
  args 
)

Definition at line 206 of file threading.py.

00206 
00207     def __exit__(self, *args):
00208         return self._lock.__exit__(*args)

Definition at line 209 of file threading.py.

00209 
00210     def __repr__(self):
00211         return "<Condition(%s, %d)>" % (self._lock, len(self._waiters))

def threading._Condition._acquire_restore (   self,
  x 
) [private]

Definition at line 215 of file threading.py.

00215 
00216     def _acquire_restore(self, x):
00217         self._lock.acquire()           # Ignore saved state

def threading._Condition._is_owned (   self) [private]

Definition at line 218 of file threading.py.

00218 
00219     def _is_owned(self):
00220         # Return True if lock is owned by current_thread.
00221         # This method is called only if __lock doesn't have _is_owned().
00222         if self._lock.acquire(0):
00223             self._lock.release()
00224             return False
00225         else:
00226             return True

def threading._Condition._release_save (   self) [private]

Definition at line 212 of file threading.py.

00212 
00213     def _release_save(self):
00214         self._lock.release()           # No state to save

def threading._Condition.notify (   self,
  n = 1 
)

Definition at line 285 of file threading.py.

00285 
00286     def notify(self, n=1):
00287         if not self._is_owned():
00288             raise RuntimeError("cannot notify on un-acquired lock")
00289         __waiters = self._waiters
00290         waiters = __waiters[:n]
00291         if not waiters:
00292             if __debug__:
00293                 self._note("%s.notify(): no waiters", self)
00294             return
00295         self._note("%s.notify(): notifying %d waiter%s", self, n,
00296                    n!=1 and "s" or "")
00297         for waiter in waiters:
00298             waiter.release()
00299             try:
00300                 __waiters.remove(waiter)
00301             except ValueError:
00302                 pass

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 303 of file threading.py.

00303 
00304     def notify_all(self):
00305         self.notify(len(self._waiters))

Here is the call graph for this function:

def threading._Condition.wait (   self,
  timeout = None 
)

Definition at line 227 of file threading.py.

00227 
00228     def wait(self, timeout=None):
00229         if not self._is_owned():
00230             raise RuntimeError("cannot wait on un-acquired lock")
00231         waiter = _allocate_lock()
00232         waiter.acquire()
00233         self._waiters.append(waiter)
00234         saved_state = self._release_save()
00235         try:    # restore state no matter what (e.g., KeyboardInterrupt)
00236             if timeout is None:
00237                 waiter.acquire()
00238                 gotit = True
00239                 if __debug__:
00240                     self._note("%s.wait(): got it", self)
00241             else:
00242                 if timeout > 0:
00243                     gotit = waiter.acquire(True, timeout)
00244                 else:
00245                     gotit = waiter.acquire(False)
00246                 if not gotit:
00247                     if __debug__:
00248                         self._note("%s.wait(%s): timed out", self, timeout)
00249                     try:
00250                         self._waiters.remove(waiter)
00251                     except ValueError:
00252                         pass
00253                 else:
00254                     if __debug__:
00255                         self._note("%s.wait(%s): got it", self, timeout)
00256             return gotit
00257         finally:
00258             self._acquire_restore(saved_state)

Here is the call graph for this function:

Here is the caller graph for this function:

def threading._Condition.wait_for (   self,
  predicate,
  timeout = None 
)

Definition at line 259 of file threading.py.

00259 
00260     def wait_for(self, predicate, timeout=None):
00261         endtime = None
00262         waittime = timeout
00263         result = predicate()
00264         while not result:
00265             if waittime is not None:
00266                 if endtime is None:
00267                     endtime = _time() + waittime
00268                 else:
00269                     waittime = endtime - _time()
00270                     if waittime <= 0:
00271                         if __debug__:
00272                             self._note("%s.wait_for(%r, %r): Timed out.",
00273                                        self, predicate, timeout)
00274                         break
00275             if __debug__:
00276                 self._note("%s.wait_for(%r, %r): Waiting with timeout=%s.",
00277                            self, predicate, timeout, waittime)
00278             self.wait(waittime)
00279             result = predicate()
00280         else:
00281             if __debug__:
00282                 self._note("%s.wait_for(%r, %r): Success.",
00283                            self, predicate, timeout)
00284         return result

Here is the call graph for this function:


Member Data Documentation

Definition at line 194 of file threading.py.

Definition at line 198 of file threading.py.

Definition at line 182 of file threading.py.

Definition at line 190 of file threading.py.

Definition at line 201 of file threading.py.

Definition at line 184 of file threading.py.

Definition at line 306 of file threading.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 185 of file threading.py.


The documentation for this class was generated from the following file: