ok

Mini Shell

Direktori : /usr/lib64/python3.6/asyncio/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/asyncio/__pycache__/tasks.cpython-36.pyc

3


 \�a�
@s�dZddddddddd	d
ddd
g
ZddlZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZddlmZddlm
Z
ddlmZGdd�de
j�ZeZyddlZWnek
r�YnXejZZej
jZej
jZej
jZedded�dd��Zdd�Zedd�dd��Zedd��Zddd �d!d�Zed/dd�d"d��Zdd�d#d$�Zee�d	<d	e_ [dd�d%d�Z!ed&d'��Z"Gd(d)�d)e
j�Z#dd*d+�d,d
�Z$dd�d-d�Z%d.d
�Z&dS)0z0Support for tasks, coroutines and the scheduler.�Task�FIRST_COMPLETED�FIRST_EXCEPTION�
ALL_COMPLETED�wait�wait_for�as_completed�sleep�async�gather�shield�
ensure_future�run_coroutine_threadsafe�N�)�
base_tasks)�compat)�
coroutines)�events)�futures)�	coroutinecs�eZdZdZej�ZiZdZe	ddd��Z
e	ddd��Zdd��fd	d
�
Ze
jrXdd�Zd
d�Zdd�dd�Zddd�dd�Zdd�Zd�fdd�	Zdd�Z�ZS)rz A coroutine wrapped in a Future.TNcCs|dkrtj�}|jj|�S)z�Return the currently running task in an event loop or None.

        By default the current task for the current event loop is returned.

        None is returned when called not in the context of a Task.
        N)r�get_event_loop�_current_tasks�get)�cls�loop�r�/usr/lib64/python3.6/tasks.py�current_task.szTask.current_taskcs$�dkrtj���fdd�|jD�S)z|Return a set of all tasks for an event loop.

        By default all tasks for the current event loop are returned.
        Ncsh|]}|j�kr|�qSr)�_loop)�.0�t)rrr�	<setcomp>Bsz!Task.all_tasks.<locals>.<setcomp>)rr�
_all_tasks)rrr)rr�	all_tasks:szTask.all_tasks)rcsdtj|�stt|���t�j|d�|jr2|jd=||_d|_d|_	|j
j|j�|j
jj|�dS)N)rrF���)r�iscoroutine�AssertionError�repr�super�__init__�_source_traceback�_coro�_fut_waiter�_must_cancelr�	call_soon�_step�	__class__r"�add)�self�coror)r0rrr)Dsz
Task.__init__cCsH|jtjkr8|jr8|dd�}|jr,|j|d<|jj|�tjj|�dS)Nz%Task was destroyed but it is pending!)�task�messageZsource_traceback)	Z_staterZ_PENDING�_log_destroy_pendingr*rZcall_exception_handler�Future�__del__)r2�contextrrrr8Ss
zTask.__del__cCs
tj|�S)N)rZ_task_repr_info)r2rrr�
_repr_info^szTask._repr_info)�limitcCstj||�S)a�Return the list of stack frames for this task's coroutine.

        If the coroutine is not done, this returns the stack where it is
        suspended.  If the coroutine has completed successfully or was
        cancelled, this returns an empty list.  If the coroutine was
        terminated by an exception, this returns the list of traceback
        frames.

        The frames are always ordered from oldest to newest.

        The optional limit gives the maximum number of frames to
        return; by default all available frames are returned.  Its
        meaning differs depending on whether a stack or a traceback is
        returned: the newest frames of a stack are returned, but the
        oldest frames of a traceback are returned.  (This matches the
        behavior of the traceback module.)

        For reasons beyond our control, only one stack frame is
        returned for a suspended coroutine.
        )rZ_task_get_stack)r2r;rrr�	get_stackaszTask.get_stack)r;�filecCstj|||�S)anPrint the stack or traceback for this task's coroutine.

        This produces output similar to that of the traceback module,
        for the frames retrieved by get_stack().  The limit argument
        is passed to get_stack().  The file argument is an I/O stream
        to which the output is written; by default output is written
        to sys.stderr.
        )rZ_task_print_stack)r2r;r=rrr�print_stackxs	zTask.print_stackcCs4d|_|j�rdS|jdk	r*|jj�r*dSd|_dS)a�Request that this task cancel itself.

        This arranges for a CancelledError to be thrown into the
        wrapped coroutine on the next cycle through the event loop.
        The coroutine then has a chance to clean up or even deny
        the request using try/except/finally.

        Unlike Future.cancel, this does not guarantee that the
        task will be cancelled: the exception might be caught and
        acted upon, delaying cancellation of the task or preventing
        cancellation completely.  The task may also return a value or
        raise a different exception.

        Immediately after this method is called, Task.cancelled() will
        not return True (unless the task was already cancelled).  A
        task will be marked as cancelled when the wrapped coroutine
        terminates with a CancelledError exception (even if cancel()
        was not called).
        FNT)Z_log_traceback�doner,�cancelr-)r2rrrr@�s

zTask.cancelcs�|j�stdj||���|jr:t|tj�s4tj�}d|_|j}d|_||j	j
|j<�zy"|dkrn|jd�}n
|j
|�}Wn�tk
r�}z.|jr�d|_|jtj��n|j|j�WYdd}~X�n�tjk
r�t�j�Y�n~tk
�r}z|j|�WYdd}~X�nPtk
�rD}z|j|��WYdd}~X�n Xt|dd�}|dk	�r|j|jk	�r�|jj|jtdj||���n||�r�||k�r�|jj|jtdj|���n2d|_|j|j�||_|j�r|jj��rd|_n|jj|jtdj||���n^|dk�r |jj|j�nDtj|��rJ|jj|jtdj||���n|jj|jtdj|���Wd|j	j
j|j�d}XdS)	Nz!_step(): already done: {!r}, {!r}F�_asyncio_future_blockingz6Task {!r} got Future {!r} attached to a different loopz!Task cannot await on itself: {!r}z;yield was used instead of yield from in task {!r} with {!r}zIyield was used instead of yield from for generator in task {!r} with {!r}zTask got bad yield: {!r}) r?r&�formatr-�
isinstancer�CancelledErrorr+r,r0rr�send�throw�
StopIteration�
set_exception�
set_result�valuer(r@�	Exception�
BaseException�getattrr.r/�RuntimeErrorrA�add_done_callback�_wakeup�inspectZisgenerator�pop)r2�excr3�resultZblocking)r0rrr/�s�



z
Task._stepcCsJy|j�Wn,tk
r8}z|j|�WYdd}~Xn
X|j�d}dS)N)rTrKr/)r2�futurerSrrrrP�szTask._wakeup)N)N)N)�__name__�
__module__�__qualname__�__doc__�weakref�WeakSetr"rr6�classmethodrr#r)rZPY34r8r:r<r>r@r/rP�
__classcell__rr)r0rrs"	!T)r�timeout�return_whenc#s�tj|�stj|�r&tdt|�j��|s2td��|tt	t
fkrNtdj|����dkr^tj
���fdd�t|�D�}t|||��EdHS)a�Wait for the Futures and coroutines given by fs to complete.

    The sequence futures must not be empty.

    Coroutines will be wrapped in Tasks.

    Returns two sets of Future: (done, pending).

    Usage:

        done, pending = yield from asyncio.wait(fs)

    Note: This does not raise TimeoutError! Futures that aren't done
    when the timeout occurs are returned in the second set.
    z expect a list of futures, not %sz#Set of coroutines/Futures is empty.zInvalid return_when value: {}Ncsh|]}t|�d��qS))r)r)r�f)rrrr!7szwait.<locals>.<setcomp>)r�isfuturerr%�	TypeError�typerV�
ValueErrorrrrrBrr�set�_wait)�fsrr^r_r)rrrscGs|j�s|jd�dS)N)r?rI)�waiter�argsrrr�_release_waiter<srj)rccs�|dkrtj�}|dkr"|EdHS|j�}|j|t|�}tjt|�}t||d�}|j|�zhy|EdHWn*t	j
k
r�|j|�|j��YnX|j
�r�|j�S|j|�|j�t	j��Wd|j�XdS)a�Wait for the single Future or coroutine to complete, with timeout.

    Coroutine will be wrapped in Task.

    Returns result of the Future or coroutine.  When a timeout occurs,
    it cancels the task and raises TimeoutError.  To avoid the task
    cancellation, wrap it in shield().

    If the wait is cancelled, the task is also cancelled.

    This function is a coroutine.
    N)r)rr�
create_future�
call_laterrj�	functools�partialrrOrrD�remove_done_callbackr@r?rT�TimeoutError)�futr^rrh�timeout_handle�cbrrrrAs,



c#s�|std��|j��d�|dk	r.|j|t���t|������fdd�}x|D]}|j|�qNWz�EdHWd�dk	r��j�Xt�t�}}x4|D],}|j|�|j	�r�|j
|�q�|j
|�q�W||fS)zeInternal helper for wait() and wait_for().

    The fs argument must be a collection of Futures.
    zSet of Futures is empty.Ncs\�d8��dks6�tks6�tkrX|j�rX|j�dk	rX�dk	rF�j��j�sX�jd�dS)Nrr)rr�	cancelled�	exceptionr@r?rI)r`)�counterr_rrrhrr�_on_completion|sz_wait.<locals>._on_completion)r&rkrlrj�lenrOr@reror?r1)rgr^r_rrwr`r?�pendingr)rvr_rrrhrrfos(



rf)rr^c#s�tj|�stj|�r&tdt|�j���dk	r2�ntj���fdd�t	|�D��ddl
m}|�d��d����fdd	�}���fd
d��t�fdd
��}x�D]}|j
��q�W�r�|dk	rʈj||��xtt���D]}|�Vq�WdS)amReturn an iterator whose values are coroutines.

    When waiting for the yielded coroutines you'll get the results (or
    exceptions!) of the original Futures (or coroutines), in the order
    in which and as soon as they complete.

    This differs from PEP 3148; the proper way to use this is:

        for f in as_completed(fs):
            result = yield from f  # The 'yield from' may raise.
            # Use result.

    If a timeout is specified, the 'yield from' will raise
    TimeoutError when the timeout occurs before all Futures are done.

    Note: The futures 'f' are not necessarily members of fs.
    z expect a list of futures, not %sNcsh|]}t|�d��qS))r)r)rr`)rrrr!�szas_completed.<locals>.<setcomp>r)�Queue)rcs.x �D]}|j���jd�qW�j�dS)N)ro�
put_nowait�clear)r`)rwr?�todorr�_on_timeout�s

z!as_completed.<locals>._on_timeoutcs6�sdS�j|��j|��r2�dk	r2�j�dS)N)�remover{r@)r`)r?rrr}rrrw�s

z$as_completed.<locals>._on_completionc3s$�j�EdH}|dkrtj�|j�S)N)rrrprT)r`)r?rr�
_wait_for_one�sz#as_completed.<locals>._wait_for_one)rrarr%rbrcrVrrreZqueuesrzrrOrl�rangerx)rgrr^rzr~r�r`�_r)rwr?rrrr}rr�s 

c
csX|dkrdV|S|dkr"tj�}|j�}|jj|tj||�}z
|EdHS|j�XdS)z9Coroutine that completes after a given time (in seconds).rN)rrrkrrlrZ_set_result_unless_cancelledr@)ZdelayrTrrU�hrrrr�s
cCstjdtdd�t||d�S)z�Wrap a coroutine in a future.

    If the argument is a Future, it is returned directly.

    This function is deprecated in 3.5. Use asyncio.ensure_future() instead.
    z;asyncio.async() function is deprecated, use ensure_future()�)�
stacklevel)r)�warnings�warn�DeprecationWarningr)�coro_or_futurerrrr�async_�sr�cCs�tj|�r(|dk	r$||jk	r$td��|Stj|�r^|dkrBtj�}|j|�}|j	rZ|j	d=|St
jr~tj
|�r~tt|�|d�Std��dS)zmWrap a coroutine or an awaitable in a future.

    If the argument is a Future, it is returned directly.
    Nz$loop argument must agree with Futurer)rz:An asyncio.Future, a coroutine or an awaitable is requiredr$)rrarrdrr%rrZcreate_taskr*rZPY35rQZisawaitabler�_wrap_awaitablerb)r�rr4rrrr�s


ccs|j�EdHS)z�Helper for asyncio.ensure_future().

    Wraps awaitable (an object with __await__) into a coroutine
    that will later be wrapped in a Task by ensure_future().
    N)�	__await__)Z	awaitablerrrr�sr�cs.eZdZdZdd��fdd�
Zdd�Z�ZS)�_GatheringFuturez�Helper for gather().

    This overrides cancel() to cancel all the children and act more
    like Task.cancel(), which doesn't immediately mark itself as
    cancelled.
    N)rcst�j|d�||_d|_dS)N)rF)r(r)�	_children�_cancel_requested)r2�childrenr)r0rrr)$sz_GatheringFuture.__init__cCs:|j�rdSd}x|jD]}|j�rd}qW|r6d|_|S)NFT)r?r�r@r�)r2ZretZchildrrrr@)sz_GatheringFuture.cancel)rVrWrXrYr)r@r]rr)r0rr�sr�F)r�return_exceptionscs|s*|dkrtj�}|j���jg��Si�xjt|�D]^}tj|�sht||d�}|dkr`|j}d|_	n&|}|dkr||j}n|j|k	r�t
d��|�|<q8W�fdd�|D�}t|��t||d��d�dg�������fdd	�}x&t
|�D]\}}|jtj||��q�W�S)
a7Return a future aggregating results from the given coroutines
    or futures.

    Coroutines will be wrapped in a future and scheduled in the event
    loop. They will not necessarily be scheduled in the same order as
    passed in.

    All futures must share the same event loop.  If all the tasks are
    done successfully, the returned future's result is the list of
    results (in the order of the original sequence, not necessarily
    the order of results arrival).  If *return_exceptions* is True,
    exceptions in the tasks are treated the same as successful
    results, and gathered in the result list; otherwise, the first
    raised exception will be immediately propagated to the returned
    future.

    Cancellation: if the outer Future is cancelled, all children (that
    have not completed yet) are also cancelled.  If any child is
    cancelled, this is treated as if it raised CancelledError --
    the outer Future is *not* cancelled in this case.  (This is to
    prevent the cancellation of one child to cause other children to
    be cancelled.)
    N)rFz)futures are tied to different event loopscsg|]}�|�qSrr)r�arg)�
arg_to_futrr�
<listcomp>hszgather.<locals>.<listcomp>rcs��j�r|j�s|j�dS|j�r@tj�}�sl�j|�dSn,|jdk	rf|j�}�sl�j|�dSn|j}|�|<�d7���kr��jr��jtj��n
�j	��dS)Nr)
r?rtrurrDrHZ
_exceptionZ_resultr�rI)�irq�res)�	nchildren�	nfinished�outer�resultsr�rr�_done_callbackns*


zgather.<locals>._done_callback)rrrkrIrerrarrr6rdrxr��	enumeraterOrmrn)rr�Zcoros_or_futuresr�rqr�r�r�r)r�r�r�r�r�r�rr
8s8



cs@t||d�}|j�r|S|j}|j���fdd�}|j|��S)a=Wait for a future, shielding it from cancellation.

    The statement

        res = yield from shield(something())

    is exactly equivalent to the statement

        res = yield from something()

    *except* that if the coroutine containing it is cancelled, the
    task running in something() is not cancelled.  From the POV of
    something(), the cancellation did not happen.  But its caller is
    still cancelled, so the yield-from expression still raises
    CancelledError.  Note: If something() is cancelled by other means
    this will still cancel shield().

    If you want to completely ignore cancellation (not recommended)
    you can combine shield() with a try/except clause, as follows:

        try:
            res = yield from shield(something())
        except CancelledError:
            res = None
    )rcs\�j�r|j�s|j�dS|j�r.�j�n*|j�}|dk	rJ�j|�n�j|j��dS)N)rtrur@rHrIrT)�innerrS)r�rrr��s
zshield.<locals>._done_callback)rr?rrkrO)r�rr�r�r)r�rr�s
cs:tj��std��tjj�����fdd�}�j|��S)zsSubmit a coroutine object to a given event loop.

    Return a concurrent.futures.Future to access the result.
    zA coroutine object is requiredcsTytjt��d���Wn6tk
rN}z�j�r<�j|��WYdd}~XnXdS)N)r)rZ
_chain_futurerrKZset_running_or_notify_cancelrH)rS)r3rUrrr�callback�s
z*run_coroutine_threadsafe.<locals>.callback)rr%rb�
concurrentrr7Zcall_soon_threadsafe)r3rr�r)r3rUrrr
�s


)N)'rY�__all__�concurrent.futuresr�rmrQr�rZ�rrrrrrr7rZ_PyTaskZ_asyncio�ImportErrorZ_CTaskrrrrrjrrfrrr��globalsrVrr�r�r
rr
rrrr�<module>sZ
s
--8

W5

Zerion Mini Shell 1.0