Yf: @ s d Z d d d d d g Z d d l Z d d l m Z d d
l m Z d d l m Z d d l m Z Gd
d d Z Gd d d Z
Gd d d e
Z Gd d d Z Gd d d e
Z
Gd d d e
Z Gd d d e Z d S)zSynchronization primitives.LockEvent Condition SemaphoreBoundedSemaphore N )compat)events)futures) coroutinec @ s: e Z d Z d Z d d Z d d Z d d Z d S) _ContextManagera Context manager.
This enables the following idiom for acquiring and releasing a
lock around a block:
with (yield from lock):
while failing loudly when accidentally using:
with lock:
c C s
| | _ d S)N)_lock)selflock r 2/opt/alt/python35/lib64/python3.5/asyncio/locks.py__init__ s z_ContextManager.__init__c C s d S)Nr )r r r r __enter__ s z_ContextManager.__enter__c G s" z | j j Wd d | _ Xd S)N)r
release)r argsr r r __exit__$ s z_ContextManager.__exit__N)__name__
__module____qualname____doc__r r r r r r r r
s
r c @ ss e Z d Z d d Z d d Z e d d Z e j ro d d Z e d d
Z
e d d Z d
S)_ContextManagerMixinc C s t d d S)Nz9"yield from" should be used as context manager expression)RuntimeError)r r r r r , s z_ContextManagerMixin.__enter__c G s d S)Nr )r r r r r r 0 s z_ContextManagerMixin.__exit__c c s | j Ed Ht | S)N)acquirer )r r r r __iter__5 s z_ContextManagerMixin.__iter__c c s | j Ed Ht | S)N)r r )r r r r __await__H s z_ContextManagerMixin.__await__c c s | j Ed Hd S)N)r )r r r r
__aenter__M s z_ContextManagerMixin.__aenter__c C s | j d S)N)r )r exc_typeexctbr r r __aexit__T s z_ContextManagerMixin.__aexit__N)r r r r r r r r ZPY35r r r$ r r r r r + s r c sp e Z d Z d Z d d d d Z f d d Z d d Z e d
d Z d d
Z d d 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 'yield from'.
Locks also support the context management protocol. '(yield from lock)'
should be used as the context manager expression.
Usage:
lock = Lock()
...
yield from lock
try:
...
finally:
lock.release()
Context manager usage:
lock = Lock()
...
with (yield from lock):
...
Lock objects can be tested for locking state:
if not lock.locked():
yield from lock
else:
# lock is acquired
...
loopNc C sC t j | _ d | _ | d k r0 | | _ n t j | _ d S)NF)collectionsdeque_waiters_locked_loopr get_event_loop)r r% r r r r s
z
Lock.__init__c sb t j } | j r d n d } | j rH d j | t | j } d j | d d | S)Nlockedunlockedz
{},waiters:{}z <{} [{}]>r )super__repr__r) r( formatlen)r resextra) __class__r r r0 s
z
Lock.__repr__c C s | j S)z Return True if lock is acquired.)r) )r r r r r, s zLock.lockedc c s | j r3 t d d | j D r3 d | _ d S| j j } | j j | zL y | Ed Hd | _ d SWn+ t j k
r | j s | j Yn XWd | j j | Xd S)zAcquire a lock.
This method blocks until the lock is unlocked, then sets it to
locked and returns True.
c s s | ] } | j Vq d S)N) cancelled).0wr r r