a
´iM; ã @ s� d Z dZddlZddlZddlmZ ddlmZ G dd„ dƒZG d d
„ d
eƒZG dd„ dƒZ G d
d„ deƒZ
G dd„ deƒZG dd„ deƒZdS )zSynchronization primitives.)ÚLockÚEventÚ ConditionÚ SemaphoreÚBoundedSemaphoreé Né )Úevents)Ú
exceptionsc @ s e Zd Zdd„ Zdd„ ZdS )Ú_ContextManagerMixinc à s | ¡ I d H d S ©N)Úacquire©Úself© r ú%/usr/lib64/python3.9/asyncio/locks.pyÚ
__aenter__
s z_ContextManagerMixin.__aenter__c à s | ¡ d S r )Úrelease)r Úexc_typeÚexcÚtbr r r Ú __aexit__ s z_ContextManagerMixin.__aexit__N)Ú__name__Ú
__module__Ú__qualname__r r r r r r r
s r
c sN e Zd ZdZddœdd„Z‡ fdd„Zdd „ Zd
d„ Zdd
„ Zdd„ Z ‡ Z
S )r a� Primitive lock objects.
A primitive lock is a synchronization primitive that is not owned
by a particular coroutine when locked. A primitive lock is in one
of two states, 'locked' or 'unlocked'.
It is created in the unlocked state. It has two basic methods,
acquire() and release(). When the state is unlocked, acquire()
changes the state to locked and returns immediately. When the
state is locked, acquire() blocks until a call to release() in
another coroutine changes it to unlocked, then the acquire() call
resets it to locked and returns. The release() method should only
be called in the locked state; it changes the state to unlocked
and returns immediately. If an attempt is made to release an
unlocked lock, a RuntimeError will be raised.
When more than one coroutine is blocked in acquire() waiting for
the state to turn to unlocked, only one coroutine proceeds when a
release() call resets the state to unlocked; first coroutine which
is blocked in acquire() is being processed.
acquire() is a coroutine and should be called with 'await'.
Locks also support the asynchronous context management protocol.
'async with lock' statement should be used.
Usage:
lock = Lock()
...
await lock.acquire()
try:
...
finally:
lock.release()
Context manager usage:
lock = Lock()
...
async with lock:
...
Lock objects can be tested for locking state:
if not lock.locked():
await lock.acquire()
else:
# lock is acquired
...
N©Úloopc C s: d | _ d| _|d u r t ¡ | _n|| _tjdtdd� d S ©NFú[The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.é ©Ú
stacklevel)Ú_waitersÚ_lockedr Úget_event_loopÚ_loopÚwarningsÚwarnÚDeprecationWarning©r r r r r Ú__init__M s þz
Lock.__init__c sL t ƒ ¡ }| jrdnd}| jr2|› dt| jƒ› �}d|dd… › d|› d�S © NÚlockedÚunlockedú
, waiters:ú