ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python39/lib64/python3.9/asyncio/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python39/lib64/python3.9/asyncio/__pycache__/locks.cpython-39.pyc

a

���eM;�@s�dZdZddlZddlZddlmZddlmZGdd�d�ZGd	d
�d
e�ZGdd�d�Z	Gd
d�de�Z
Gdd�de�ZGdd�de�ZdS)zSynchronization primitives.)�Lock�Event�	Condition�	Semaphore�BoundedSemaphore�N�)�events)�
exceptionsc@seZdZdd�Zdd�ZdS)�_ContextManagerMixinc�s|��IdHdS�N)�acquire��self�r�2/opt/alt/python39/lib64/python3.9/asyncio/locks.py�
__aenter__
sz_ContextManagerMixin.__aenter__c�s|��dSr)�release)r�exc_type�exc�tbrrr�	__aexit__sz_ContextManagerMixin.__aexit__N)�__name__�
__module__�__qualname__rrrrrrr
sr
csNeZdZdZdd�dd�Z�fdd�Zdd	�Zd
d�Zdd
�Zdd�Z	�Z
S)ra�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��loopcCs:d|_d|_|dur t��|_n||_tjdtdd�dS�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�rrrrr�__init__Ms�z
Lock.__init__csLt���}|jrdnd}|jr2|�dt|j���}d|dd��d|�d�S�	N�lockedZunlocked�
, waiters:�<r���� [�]>)�super�__repr__r"r!�len�r�resZextra��	__class__rrr2Xs

z
Lock.__repr__cCs|jS)z Return True if lock is acquired.)r"r
rrrr+_szLock.lockedc	�s�|js.|jdus$tdd�|jD��r.d|_dS|jdurBt��|_|j��}|j�|�z.z|IdHW|j�|�n|j�|�0Wn$t	j
y�|js�|���Yn0d|_dS)z�Acquire a lock.

        This method blocks until the lock is unlocked, then sets it to
        locked and returns True.
        Ncss|]}|��VqdSr)�	cancelled)�.0�wrrr�	<genexpr>j�zLock.acquire.<locals>.<genexpr>T)r"r!�all�collections�dequer$�
create_future�append�remover	�CancelledError�_wake_up_first�r�futrrrrcs&�


 zLock.acquirecCs"|jrd|_|��ntd��dS)aGRelease a 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.
        FzLock is not acquired.N)r"rD�RuntimeErrorr
rrrr�s
zLock.releasecCsH|js
dSztt|j��}Wnty0YdS0|��sD|�d�dS)z*Wake up the first waiter if it isn't done.NT)r!�next�iter�
StopIteration�done�
set_resultrErrrrD�szLock._wake_up_first)rrr�__doc__r)r2r+rrrD�
__classcell__rrr6rrs5 rcsNeZdZdZdd�dd�Z�fdd�Zdd	�Zd
d�Zdd
�Zdd�Z	�Z
S)ra#Asynchronous equivalent to threading.Event.

    Class implementing event objects. An event manages a flag that can be set
    to true with the set() method and reset to false with the clear() method.
    The wait() method blocks until the flag is true. The flag is initially
    false.
    NrcCs>t��|_d|_|dur$t��|_n||_tjdt	dd�dSr)
r>r?r!�_valuerr#r$r%r&r'r(rrrr)�s
�zEvent.__init__csLt���}|jrdnd}|jr2|�dt|j���}d|dd��d|�d�S)	N�setZunsetr,r-rr.r/r0)r1r2rOr!r3r4r6rrr2�s

zEvent.__repr__cCs|jS)z5Return True if and only if the internal flag is true.�rOr
rrr�is_set�szEvent.is_setcCs.|js*d|_|jD]}|��s|�d�qdS)z�Set the internal flag to true. All coroutines waiting for it to
        become true are awakened. Coroutine that call wait() once the flag is
        true will not block at all.
        TN)rOr!rKrLrErrrrP�s

z	Event.setcCs
d|_dS)z�Reset the internal flag to false. Subsequently, coroutines calling
        wait() will block until set() is called to set the internal flag
        to true again.FNrQr
rrr�clear�szEvent.clearc	�sP|jr
dS|j��}|j�|�z|IdHW|j�|�dS|j�|�0dS)z�Block until the internal flag is true.

        If the internal flag is true on entry, return True
        immediately.  Otherwise, block until another coroutine calls
        set() to set the flag to true, then return True.
        TN)rOr$r@r!rArBrErrr�wait�s

�z
Event.wait)rrrrMr)r2rRrPrSrTrNrrr6rr�srcsReZdZdZddd�dd�Z�fdd�Zdd	�Zd
d�Zdd
d�Zdd�Z	�Z
S)raAsynchronous 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.

    A new Lock object is created and used as the underlying lock.
    NrcCs~|durt��|_n||_tjdtdd�|dur>t|d�}n|j|jurRtd��||_|j	|_	|j
|_
|j|_t�
�|_dS)Nrrrrz"loop argument must agree with lock)rr#r$r%r&r'r�
ValueError�_lockr+rrr>r?r!)r�lockrrrrr)�s�zCondition.__init__csNt���}|��rdnd}|jr4|�dt|j���}d|dd��d|�d�Sr*)r1r2r+r!r3r4r6rrr2s

zCondition.__repr__c�s.|��std��|��z�|j��}|j�|�z^|IdHW|j�|�Wd}z|��IdHWq�WqPt	j
y~d}YqP0qP|r�t	j
�dS|j�|�0Wd}z|��IdHWq�Wq�t	j
y�d}Yq�0q�|r�t	j
�nHd}z|��IdHW�qWq�t	j
�yd}Yq�0q�|�r(t	j
�0dS)a�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.
        zcannot wait on un-acquired lockNFT)r+rGrr$r@r!rArBrr	rC)rrFr8rrrrTsJ

���
zCondition.waitc�s$|�}|s |��IdH|�}q|S)z�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.
        N)rT)rZ	predicate�resultrrr�wait_for4s
zCondition.wait_forrcCsJ|��std��d}|jD]*}||kr*qF|��s|d7}|�d�qdS)aBy 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.
        z!cannot notify on un-acquired lockrrFN)r+rGr!rKrL)r�n�idxrFrrr�notifyAs
zCondition.notifycCs|�t|j��dS)aWake up all threads waiting on this condition. This method acts
        like notify(), but wakes up all waiting threads instead of one. If the
        calling thread has not acquired the lock when this method is called,
        a RuntimeError is raised.
        N)r\r3r!r
rrr�
notify_allYszCondition.notify_all)N)r)rrrrMr)r2rTrYr\r]rNrrr6rr�s	%
rcsPeZdZdZddd�dd�Z�fdd�Zd	d
�Zdd�Zd
d�Zdd�Z	�Z
S)raA Semaphore implementation.

    A semaphore manages an internal counter which is decremented by each
    acquire() call and incremented by each release() call. The counter
    can never go below zero; when acquire() finds that it is zero, it blocks,
    waiting until some other thread calls release().

    Semaphores also support the context management protocol.

    The optional argument gives the initial value for the internal
    counter; it defaults to 1. If the value given is less than 0,
    ValueError is raised.
    rNrcCsT|dkrtd��||_t��|_|dur4t��|_n||_tj	dt
dd�d|_dS)Nrz$Semaphore initial value must be >= 0rrrF)rUrOr>r?r!rr#r$r%r&r'�_wakeup_scheduled�r�valuerrrrr)qs
�zSemaphore.__init__csVt���}|��rdn
d|j��}|jr<|�dt|j���}d|dd��d|�d�S)	Nr+zunlocked, value:r,r-rr.r/r0)r1r2r+rOr!r3r4r6rrr2s

zSemaphore.__repr__cCs2|jr.|j��}|��s|�d�d|_dSqdS)NT)r!�popleftrKrLr^)rZwaiterrrr�
_wake_up_next�s

zSemaphore._wake_up_nextcCs
|jdkS)z:Returns True if semaphore can not be acquired immediately.rrQr
rrrr+�szSemaphore.lockedc�sn|js|jdkr\|j��}|j�|�z|IdHd|_WqtjyX|���Yq0q|jd8_dS)a5Acquire a semaphore.

        If the internal counter is larger than zero on entry,
        decrement it by one and return True immediately.  If it is
        zero on entry, block, waiting until some other coroutine has
        called release() to make it larger than 0, and then return
        True.
        rNFrT)	r^rOr$r@r!rAr	rCrbrErrrr�s



zSemaphore.acquirecCs|jd7_|��dS)z�Release a semaphore, incrementing the internal counter by one.
        When it was zero on entry and another coroutine is waiting for it to
        become larger than zero again, wake up that coroutine.
        rN)rOrbr
rrrr�szSemaphore.release)r)rrrrMr)r2rbr+rrrNrrr6rrbsrcs4eZdZdZd	dd��fdd�Z�fdd�Z�ZS)
rz�A bounded semaphore implementation.

    This raises ValueError in release() if it would increase the value
    above the initial value.
    rNrcs.|rtjdtdd�||_t�j||d�dS)Nrrrr)r%r&r'�_bound_valuer1r)r_r6rrr)�s�zBoundedSemaphore.__init__cs"|j|jkrtd��t���dS)Nz(BoundedSemaphore released too many times)rOrcrUr1rr
r6rrr�szBoundedSemaphore.release)r)rrrrMr)rrNrrr6rr�s	r)
rM�__all__r>r%�rr	r
rrrrrrrrr�<module>sDzQ

Zerion Mini Shell 1.0