Package coro :: Module _coro :: Class mutex
[hide private]
[frames] | no frames]

Class mutex

object --+
         |
        mutex

Mutual Exclusion lock object.

A single thread may acquire the mutex multiple times, but it must release the lock an equal number of times.

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__len__(x)
len(x)
a new object with type S, a subtype of T
__new__(T, S, ...)
 
has_lock(...)
Determine if a particular coroutine has the lock.
 
lock(...)
Lock the mutex.
 
locked(...)
Determine if the mutex is currently locked.
 
trylock(...)
Try to lock the mutex.
 
unlock(...)
Unlock the mutex.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
  _locked
: Count of how many locks on the mutex are currently held.
  _owner
: The coroutine object that owns the lock (None if no owner).
  _waiting
: A fifo of coroutine objects waiting for the lock.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

has_lock(...)

 
Determine if a particular coroutine has the lock.
Parameters:
  • thread - : The coroutine object to check if it owns the lock. If not specified, defaults to the current thread.
Returns:
Returns True if the specified thread has the lock, otherwise returns False.

lock(...)

 

Lock the mutex.

This will block if another coro already owns the mutex.

A coro thread may lock the mutex multiple times. It must call unlock the same number of times to release it.

Returns:
Returns True if it blocked, False if the mutex was acquired immediately.

locked(...)

 
Determine if the mutex is currently locked.
Returns:
Returns True if the mutex is locked, otherwise False.

trylock(...)

 
Try to lock the mutex.
Returns:
Returns True if it is already locked by another coroutine thread. Returns False if the lock was successfully acquired.

unlock(...)

 

Unlock the mutex.

The thread unlocking must be the thread that initially locked it.

Returns:
Returns True if another thread was waiting for the lock, otherwise it returns False.

Instance Variable Details [hide private]

_owner

: The coroutine object that owns the lock (None if no owner). (C only.)