File "tasks.cpython-35.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python35/lib64/python3.5/asyncio/__pycache__/tasks.cpython-35.pyc
File size: 21.04 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit



Yfg
@sCdZddddddddd	d
ddd
g
ZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZddl
m
Z
ddl
mZddlmZGdddejZejjZejjZejjZedddddeddZddZeddddZeddZddddd dZedddd!dZddd"d#Zeed	<d	e_[ddd$dZed%d&ZGd'd(d(ejZ ddd)d*d+d
Z!ddd,dZ"d-d
Z#dS).z0Support for tasks, coroutines and the scheduler.TaskFIRST_COMPLETEDFIRST_EXCEPTION
ALL_COMPLETEDwaitwait_foras_completedsleepasyncgathershield
ensure_futurerun_coroutine_threadsafeN)compat)
coroutines)events)futures)	coroutinecseZdZdZejZiZdZe	dddZ
e	dddZddfd	d
Ze
jrddZfd
dZddddZddddddZddZdfddZddZS)rz A coroutine wrapped in a Future.TNcCs(|dkrtj}|jj|S)zReturn 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)rget_event_loop_current_tasksget)clsloopr2/opt/alt/python35/lib64/python3.5/asyncio/tasks.pycurrent_task/szTask.current_taskcs2dkrtjfdd|jDS)z|Return a set of all tasks for an event loop.

        By default all tasks for the current event loop are returned.
        Ncs%h|]}|jkr|qSr)_loop).0t)rrr	<setcomp>Cs	z!Task.all_tasks.<locals>.<setcomp>)rr
_all_tasks)rrr)rr	all_tasks;szTask.all_tasksrcstj|s!tt|tjd||jrG|jd=||_d|_d|_	|j
j|j|j
jj|dS)NrrF)riscoroutineAssertionErrorreprsuper__init___source_traceback_coro_fut_waiter_must_cancelr	call_soon_step	__class__r!add)selfcoror)r/rrr(Es!	
			z
Task.__init__cCsg|jtjkrS|jrSd|ddi}|jrC|j|d<|jj|tjj|dS)Ntaskmessagez%Task was destroyed but it is pending!Zsource_traceback)	Z_staterZ_PENDING_log_destroy_pendingr)rZcall_exception_handlerFuture__del__)r1contextrrrr7Ts	
zTask.__del__csrtj}|jr"d|d<tj|j}|jdd||jdk	rn|jdd|j|S)NZ
cancellingrrz	coro=<%s>zwait_for=%r)r'
_repr_infor,rZ_format_coroutiner*insertr+)r1infor2)r/rrr:_s	
zTask._repr_infolimitcCs
g}y|jj}Wntk
r6|jj}YnX|dk	rxI|dk	r|dk	ru|dkrkP|d8}|j||j}qFW|jnj|jdk	r|jj}xL|dk	r|dk	r|dkrP|d8}|j|j	|j
}qW|S)aReturn 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.
        Nrr)r*cr_frameAttributeErrorgi_frameappendf_backreverse
_exception
__traceback__tb_frametb_next)r1r=Zframesftbrrr	get_stackms0






zTask.get_stackfilecCs]g}t}x|jd|D]}|j}|j}|j}|j}	||krr|j|tj|tj	|||j
}
|j|||	|
fq"W|j}|st
d|d|n7|dk	rt
d|d|nt
d|d|tj|d||dk	rYx3tj|j|D]}
t
|
d|ddq9WdS)	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.
        r=zNo stack for %rrKNz)Traceback for %r (most recent call last):z%Stack for %r (most recent call last):end)setrJf_linenof_codeco_filenameco_namer0	linecache
checkcachegetline	f_globalsrArDprint	traceback
print_listformat_exception_onlyr/)r1r=rKextracted_listZcheckedrHlinenocofilenamenamelineexcrrrprint_stacks0						

	


zTask.print_stackcCsHd|_|jrdS|jdk	r;|jjr;dSd|_dS)aRequest 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_tracebackdoner+cancelr,)r1rrrrds		zTask.cancelcs@|js%tdj|||jrUt|tjsLtj}d|_|j}d|_||j	j
|j<zy1|dkr|jd}n|j
|}Wntk
r
}z=|jrd|_|jtjn|j|jWYdd}~Xntjk
r.tjYntk
r_}z|j|WYdd}~Xntk
r}z|j|WYdd}~XnXt|dd}|dk	r|j|jk	r|jj|jtdj||q|ro||kr)|jj|jtdj|qd|_|j|j||_|jr|jjrd|_q|jj|jtdj||n|dkr|jj|jn_tj|r|jj|jtdj||n%|jj|jtdj|Wd|j	j
j|jd}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}zGyield was used instead of yield from for generator in task {!r} with {}zTask got bad yield: {!r}) rcr%formatr,
isinstancerCancelledErrorr*r+r/rrsendthrow
StopIteration
set_exception
set_resultvaluer'rd	Exception
BaseExceptiongetattrr-r.RuntimeErrorreadd_done_callback_wakeupinspectZisgeneratorpop)r1rar2resultZblocking)r/rrr.s						"
								z
Task._stepcCsWy|jWn2tk
rB}z|j|WYdd}~XnX|jd}dS)N)rwror.)r1futurerarrrrt4s 
zTask._wakeup)__name__
__module____qualname____doc__weakrefWeakSetr!rr5classmethodrr"r(rZPY34r7r:rJrbrdr.rtrr)r/rrs"		/#!Trtimeoutreturn_whenc#stj|stj|r7tdt|j|sItd|tt	t
fkrstdj|dkrtj
fddt|D}t|||EdHS)aWait 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: {}Ncs"h|]}t|dqS)r)r)rrH)rrrr gs	zwait.<locals>.<setcomp>)risfuturerr$	TypeErrortypery
ValueErrorrrrrfrrrN_wait)fsrrrr)rrrLscGs|js|jddS)N)rcrm)waiterargsrrr_release_waiterlsrccs
|dkrtj}|dkr-|EdHS|j}|j|t|}tjt|}t|d|}|j|z|y
|EdHWn/t	j
k
r|j||jYnX|j
r|jS|j||jt	jWd|jXdS)aWait 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.
    Nr)rr
create_future
call_laterr	functoolspartialrrsrrhremove_done_callbackrdrcrwTimeoutError)futrrrtimeout_handlecbrrrrqs,	






c#s|std|jd|dk	rE|j|tt|fdd}x|D]}|j|qsWz
EdHWddk	rjXtt}}xD|D]<}|j||j	r|j
|q|j
|qW||fS)zeInternal helper for wait() and wait_for().

    The fs argument must be a collection of Futures.
    zSet of Futures is empty.Ncsd8dksMtksMtkr||jr||jdk	r|dk	rcjjs|jddS)Nrr)rr	cancelled	exceptionrdrcrm)rH)counterrrrrr_on_completions

z_wait.<locals>._on_completion)r%rrrlenrsrdrNrrcr0)rrrrrrHrcpendingr)rrrrrrs(



rc#sLtj|stj|r7tdt|jdk	rIn	tjfddt	|Dddl
m}|ddfdd	}fd
dtfdd
}xD]}|j
qWr#|dk	r#j||x"ttD]}|Vq6WdS)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 %sNcs"h|]}t|dqS)r)r)rrH)rrrr s	zas_completed.<locals>.<setcomp>r)Queuercs9x(D] }|jjdqWjdS)N)r
put_nowaitclear)rH)rrctodorr_on_timeouts

z!as_completed.<locals>._on_timeoutcsEs
dSj|j|rAdk	rAjdS)N)removerrd)rH)rcrrrrrs

z$as_completed.<locals>._on_completionc3s0jEdH}|dkr&tj|jS)N)rrrrw)rH)rcrr
_wait_for_ones	z#as_completed.<locals>._wait_for_one)rrrr$rrryrrrNZqueuesrrrsrranger)rrrrrrrH_r)rrcrrrrrs 
c
csv|dkrdV|S|dkr-tj}|j}|jj|tj||}z
|EdHSWd|jXdS)z9Coroutine that completes after a given time (in seconds).rN)rrrrrrZ_set_result_unless_cancelledrd)Zdelayrwrrxhrrrrs
cCs&tjdtddt|d|S)zWrap 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()
stacklevelr9r)warningswarnDeprecationWarningr)coro_or_futurerrrrasync_s	rcCstj|r:|dk	r6||jk	r6td|Stj|r|dkratj}|j|}|j	r|j	d=|St
jrtj
|rtt|d|StddS)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 Futurerrz:An asyncio.Future, a coroutine or an awaitable is requiredr#)rrrrrr$rrZcreate_taskr)rZPY35ruZisawaitabler_wrap_awaitabler)rrr3rrrr+s	
ccs|jEdHS)zHelper 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	awaitablerrrrBsrcs:eZdZdZddfddZddZS)_GatheringFuturezHelper for gather().

    This overrides cancel() to cancel all the children and act more
    like Task.cancel(), which doesn't immediately mark itself as
    cancelled.
    rNcs tjd|||_dS)Nr)r'r(	_children)r1childrenr)r/rrr(Tsz_GatheringFuture.__init__cCs@|jrdSd}x#|jD]}|jr d}q W|S)NFT)rcrrd)r1ZretZchildrrrrdXs
z_GatheringFuture.cancel)ryrzr{r|r(rdrr)r/rrLsrreturn_exceptionsFcs|s;|dkrtj}|jjgSixt|D]}tj|st|d|}|dkr|j}d|_	n9|}|dkr|j}n|j|k	rt
d||<qNWfdd|D}t|t|d|ddgfdd	}x3t
|D]%\}}|jtj||qRWS)
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.)
    NrFz)futures are tied to different event loopscsg|]}|qSrr)rarg)
arg_to_futrr
<listcomp>s	zgather.<locals>.<listcomp>rcsjr&|js"|jdS|jrXtj}sj|dSn>|jdk	r|j}sj|dSn	|j}||<d7krjdS)Nr)	rcrrrrhrlrDZ_resultrm)irres)	nchildren	nfinishedouterresultsrrr_done_callbacks&


	

zgather.<locals>._done_callback)rrrrmrNrrrrr5rrr	enumeratersrr)rrZcoros_or_futuresrrrrrr)rrrrrrrr
bs8
	
csZt|d|}|jr"|S|j}|jfdd}|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~jr&|js"|jdS|jr?jn;|j}|dk	rgj|nj|jdS)N)rrrdrlrmrw)innerra)rrrrs

zshield.<locals>._done_callback)rrcrrrs)rrrrr)rrrs	
csStjstdtjjfdd}j|S)zsSubmit a coroutine object to a given event loop.

    Return a concurrent.futures.Future to access the result.
    zA coroutine object is requiredcshy tjtdWnAtk
rc}z!jrNj|WYdd}~XnXdS)Nr)rZ
_chain_futurerroZset_running_or_notify_cancelrl)ra)r2rxrrrcallbacks 
z*run_coroutine_threadsafe.<locals>.callback)rr$r
concurrentrr6Zcall_soon_threadsafe)r2rrr)r2rxrrr
s
)$r|__all__Zconcurrent.futuresrrrurSrXrr}rMrrrrrr6rrrrrrrrrrrglobalsryrrrr
rr
rrrr<module>sP	0--8
	
T5