asyncio.Condition

class asyncio.Condition(lock=None, *, loop=None)

A Condition implementation, asynchronous equivalent to threading.Condition.

This class implements condition variable objects. A condition variable allows one or more coroutines to wait until they are notified by another coroutine.

If the lock argument is given and not None, it must be a Lock object, and it is used as the underlying lock. Otherwise, a new Lock object is created and used as the underlying lock.

This class is not thread safe.

coroutine acquire()

Acquire the underlying lock.

This method blocks until the lock is unlocked, then sets it to locked and returns True.

This method is a coroutine.

notify(n=1)

By default, wake up one coroutine waiting on this condition, if any. If the calling coroutine has not acquired the lock when this method is called, a RuntimeError is raised.

This method wakes up at most n of the coroutines waiting for the condition variable; it is a no-op if no coroutines are waiting.

Note

An awakened coroutine does not actually return from its wait() call until it can reacquire the lock. Since notify() does not release the lock, its caller should.

locked()

Return True if the underlying lock is acquired.

notify_all()

Wake up all coroutines waiting on this condition. This method acts like notify(), but wakes up all waiting coroutines instead of one. If the calling coroutine has not acquired the lock when this method is called, a RuntimeError is raised.

release()

Release the underlying lock.

When the lock is locked, reset it to unlocked, and return. If any other coroutines are blocked waiting for the lock to become unlocked, allow exactly one of them to proceed.

When invoked on an unlocked lock, a RuntimeError is raised.

There is no return value.

coroutine wait()

Wait until notified.

If the calling coroutine has not acquired the lock when this method is called, a RuntimeError is raised.

This method releases the underlying lock, and then blocks until it is awakened by a notify() or notify_all() call for the same condition variable in another coroutine. Once awakened, it re-acquires the lock and returns True.

This method is a coroutine.

coroutine wait_for(predicate)

Wait until a predicate becomes true.

The predicate should be a callable which result will be interpreted as a boolean value. The final predicate value is the return value.

This method is a coroutine.

doc_python
2016-10-07 17:26:43
Comments
Leave a Comment

Please login to continue.