Back to index

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

List of all members.

Public Member Functions

def __init__
def acquire
def release
def __exit__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Attributes

 _cond
 _value

Static Private Attributes

 __enter__ = acquire

Detailed Description

Definition at line 312 of file threading.py.


Constructor & Destructor Documentation

def threading._Semaphore.__init__ (   self,
  value = 1,
  verbose = None 
)

Reimplemented in threading._BoundedSemaphore.

Definition at line 316 of file threading.py.

00316 
00317     def __init__(self, value=1, verbose=None):
00318         if value < 0:
00319             raise ValueError("semaphore initial value must be >= 0")
00320         _Verbose.__init__(self, verbose)
00321         self._cond = Condition(Lock())
00322         self._value = value

Here is the caller graph for this function:


Member Function Documentation

def threading._Semaphore.__exit__ (   self,
  t,
  v,
  tb 
)

Definition at line 363 of file threading.py.

00363 
00364     def __exit__(self, t, v, tb):
00365         self.release()
00366 

Here is the call graph for this function:

def threading._Semaphore.acquire (   self,
  blocking = True,
  timeout = None 
)

Definition at line 323 of file threading.py.

00323 
00324     def acquire(self, blocking=True, timeout=None):
00325         if not blocking and timeout is not None:
00326             raise ValueError("can't specify timeout for non-blocking acquire")
00327         rc = False
00328         endtime = None
00329         self._cond.acquire()
00330         while self._value == 0:
00331             if not blocking:
00332                 break
00333             if __debug__:
00334                 self._note("%s.acquire(%s): blocked waiting, value=%s",
00335                            self, blocking, self._value)
00336             if timeout is not None:
00337                 if endtime is None:
00338                     endtime = _time() + timeout
00339                 else:
00340                     timeout = endtime - _time()
00341                     if timeout <= 0:
00342                         break
00343             self._cond.wait(timeout)
00344         else:
00345             self._value = self._value - 1
00346             if __debug__:
00347                 self._note("%s.acquire: success, value=%s",
00348                            self, self._value)
00349             rc = True
00350         self._cond.release()
00351         return rc

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented in threading._BoundedSemaphore.

Definition at line 354 of file threading.py.

00354 
00355     def release(self):
00356         self._cond.acquire()
00357         self._value = self._value + 1
00358         if __debug__:
00359             self._note("%s.release: success, value=%s",
00360                        self, self._value)
00361         self._cond.notify()
00362         self._cond.release()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 352 of file threading.py.

Definition at line 320 of file threading.py.

Definition at line 321 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.


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