Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
multiprocessing.synchronize.Condition Class Reference
Inheritance diagram for multiprocessing.synchronize.Condition:
Inheritance graph
[legend]
Collaboration diagram for multiprocessing.synchronize.Condition:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __getstate__
def __setstate__
def __enter__
def __exit__
def __repr__
def wait
def notify
def notify_all

Public Attributes

 acquire
 release
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _make_methods

Private Attributes

 _lock
 _sleeping_count
 _woken_count
 _wait_semaphore

Detailed Description

Definition at line 195 of file synchronize.py.


Constructor & Destructor Documentation

def multiprocessing.synchronize.Condition.__init__ (   self,
  lock = None 
)

Definition at line 197 of file synchronize.py.

00197 
00198     def __init__(self, lock=None):
00199         self._lock = lock or RLock()
00200         self._sleeping_count = Semaphore(0)
00201         self._woken_count = Semaphore(0)
00202         self._wait_semaphore = Semaphore(0)
00203         self._make_methods()

Here is the caller graph for this function:


Member Function Documentation

Definition at line 214 of file synchronize.py.

00214 
00215     def __enter__(self):
00216         return self._lock.__enter__()

Definition at line 217 of file synchronize.py.

00217 
00218     def __exit__(self, *args):
00219         return self._lock.__exit__(*args)

Here is the caller graph for this function:

Definition at line 204 of file synchronize.py.

00204 
00205     def __getstate__(self):
00206         assert_spawning(self)
00207         return (self._lock, self._sleeping_count,
00208                 self._woken_count, self._wait_semaphore)

Here is the call graph for this function:

Definition at line 224 of file synchronize.py.

00224 
00225     def __repr__(self):
00226         try:
00227             num_waiters = (self._sleeping_count._semlock._get_value() -
00228                            self._woken_count._semlock._get_value())
00229         except Exception:
00230             num_waiters = 'unkown'
00231         return '<Condition(%s, %s)>' % (self._lock, num_waiters)

Definition at line 209 of file synchronize.py.

00209 
00210     def __setstate__(self, state):
00211         (self._lock, self._sleeping_count,
00212          self._woken_count, self._wait_semaphore) = state
00213         self._make_methods()

Here is the call graph for this function:

Definition at line 220 of file synchronize.py.

00220 
00221     def _make_methods(self):
00222         self.acquire = self._lock.acquire
00223         self.release = self._lock.release

Here is the caller graph for this function:

Definition at line 256 of file synchronize.py.

00256 
00257     def notify(self):
00258         assert self._lock._semlock._is_mine(), 'lock is not owned'
00259         assert not self._wait_semaphore.acquire(False)
00260 
00261         # to take account of timeouts since last notify() we subtract
00262         # woken_count from sleeping_count and rezero woken_count
00263         while self._woken_count.acquire(False):
00264             res = self._sleeping_count.acquire(False)
00265             assert res
00266 
00267         if self._sleeping_count.acquire(False): # try grabbing a sleeper
00268             self._wait_semaphore.release()      # wake up one sleeper
00269             self._woken_count.acquire()         # wait for the sleeper to wake
00270 
00271             # rezero _wait_semaphore in case a timeout just happened
00272             self._wait_semaphore.acquire(False)

Here is the caller graph for this function:

Definition at line 273 of file synchronize.py.

00273 
00274     def notify_all(self):
00275         assert self._lock._semlock._is_mine(), 'lock is not owned'
00276         assert not self._wait_semaphore.acquire(False)
00277 
00278         # to take account of timeouts since last notify*() we subtract
00279         # woken_count from sleeping_count and rezero woken_count
00280         while self._woken_count.acquire(False):
00281             res = self._sleeping_count.acquire(False)
00282             assert res
00283 
00284         sleepers = 0
00285         while self._sleeping_count.acquire(False):
00286             self._wait_semaphore.release()        # wake up one sleeper
00287             sleepers += 1
00288 
00289         if sleepers:
00290             for i in range(sleepers):
00291                 self._woken_count.acquire()       # wait for a sleeper to wake
00292 
00293             # rezero wait_semaphore in case some timeouts just happened
00294             while self._wait_semaphore.acquire(False):
00295                 pass
00296 
00297 #
00298 # Event
00299 #

def multiprocessing.synchronize.Condition.wait (   self,
  timeout = None 
)

Definition at line 232 of file synchronize.py.

00232 
00233     def wait(self, timeout=None):
00234         assert self._lock._semlock._is_mine(), \
00235                'must acquire() condition before using wait()'
00236 
00237         # indicate that this thread is going to sleep
00238         self._sleeping_count.release()
00239 
00240         # release lock
00241         count = self._lock._semlock._count()
00242         for i in range(count):
00243             self._lock.release()
00244 
00245         try:
00246             # wait for notification or timeout
00247             ret = self._wait_semaphore.acquire(True, timeout)
00248         finally:
00249             # indicate that this thread has woken
00250             self._woken_count.release()
00251 
00252             # reacquire lock
00253             for i in range(count):
00254                 self._lock.acquire()
00255             return ret

Here is the caller graph for this function:


Member Data Documentation

Definition at line 198 of file synchronize.py.

Definition at line 199 of file synchronize.py.

Definition at line 201 of file synchronize.py.

Definition at line 200 of file synchronize.py.

Definition at line 221 of file synchronize.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 222 of file synchronize.py.


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