/snap/core18/2979/usr/lib/python3.6/asyncio/__pycache__
NameSizeModeActions
base_events.cpython-36.pyc393450644editdlrm
base_futures.cpython-36.pyc20470644editdlrm
base_subprocess.cpython-36.pyc92620644editdlrm
base_tasks.cpython-36.pyc18610644editdlrm
compat.cpython-36.pyc7320644editdlrm
constants.cpython-36.pyc2510644editdlrm
coroutines.cpython-36.pyc85520644editdlrm
events.cpython-36.pyc253380644editdlrm
futures.cpython-36.pyc137470644editdlrm
locks.cpython-36.pyc154480644editdlrm
log.cpython-36.pyc2180644editdlrm
proactor_events.cpython-36.pyc168220644editdlrm
protocols.cpython-36.pyc59770644editdlrm
queues.cpython-36.pyc84040644editdlrm
selector_events.cpython-36.pyc295670644editdlrm
sslproto.cpython-36.pyc203430644editdlrm
streams.cpython-36.pyc199150644editdlrm
subprocess.cpython-36.pyc68240644editdlrm
tasks.cpython-36.pyc190930644editdlrm
test_utils.cpython-36.pyc176810644editdlrm
transports.cpython-36.pyc120600644editdlrm
unix_events.cpython-36.pyc305550644editdlrm
windows_events.cpython-36.pyc214940644editdlrm
windows_utils.cpython-36.pyc53820644editdlrm
__init__.cpython-36.pyc7780644editdlrm
Edit: /snap/core18/2979/usr/lib/python3.6/asyncio/__pycache__/futures.cpython-36.pyc (13747B)
3 Nqi>ã @s dZddddddgZddlZddlZddlZddlZd d lmZd d lm Z d d lm Z ej Z ej Z ej Z ejZejZejZejZejd ZGd d„dƒZGdd„dƒZeZdd„Zdd„Zdd„Zdd„Zddœdd„Zy ddlZWnek rúYn XejZZdS)z.A Future class similar to the one in PEP 3148.ÚCancelledErrorÚ TimeoutErrorÚInvalidStateErrorÚFutureÚ wrap_futureÚisfutureéNé)Ú base_futures)Úcompat)Úeventsc@s4eZdZdZdZdd„Zdd „Zd d „Zd d „ZdS)Ú_TracebackLoggera Helper to log a traceback upon destruction if not cleared. This solves a nasty problem with Futures and Tasks that have an exception set: if nobody asks for the exception, the exception is never logged. This violates the Zen of Python: 'Errors should never pass silently. Unless explicitly silenced.' However, we don't want to log the exception as soon as set_exception() is called: if the calling code is written properly, it will get the exception and handle it properly. But we *do* want to log it if result() or exception() was never called -- otherwise developers waste a lot of time wondering why their buggy code fails silently. An earlier attempt added a __del__() method to the Future class itself, but this backfired because the presence of __del__() prevents garbage collection from breaking cycles. A way out of this catch-22 is to avoid having a __del__() method on the Future class itself, but instead to have a reference to a helper object with a __del__() method that logs the traceback, where we ensure that the helper object doesn't participate in cycles, and only the Future has a reference to it. The helper object is added when set_exception() is called. When the Future is collected, and the helper is present, the helper object is also collected, and its __del__() method will log the traceback. When the Future's result() or exception() method is called (and a helper object is present), it removes the helper object, after calling its clear() method to prevent it from logging. One downside is that we do a fair amount of work to extract the traceback from the exception, even when it is never logged. It would seem cheaper to just store the exception object, but that references the traceback, which references stack frames, which may reference the Future, which references the _TracebackLogger, and then the _TracebackLogger would be included in a cycle, which is what we're trying to avoid! As an optimization, we don't immediately format the exception; we only do the work when activate() is called, which call is delayed until after all the Future's callbacks have run. Since usually a Future has at least one callback (typically set by 'yield from') and usually that callback extracts the callback, thereby removing the need to format the exception. PS. I don't claim credit for this solution. I first heard of it in a discussion about closing files when they are collected. ÚloopÚsource_tracebackÚexcÚtbcCs |j|_|j|_||_d|_dS)N)Ú_loopr Ú_source_tracebackrrr)ÚselfÚfuturer©rú%/usr/lib/python3.6/asyncio/futures.pyÚ__init__Rsz_TracebackLogger.__init__cCs,|j}|dk r(d|_tj|j||jƒ|_dS)N)rÚ tracebackÚformat_exceptionÚ __class__Ú __traceback__r)rrrrrÚactivateXs  z_TracebackLogger.activatecCsd|_d|_dS)N)rr)rrrrÚclear_sz_TracebackLogger.clearcCsb|jr^d}|jr:djtj|jƒƒ}|d7}|d|jƒ7}|dj|jƒjƒ7}|jjd|iƒdS)Nz*Future/Task exception was never retrieved Úz0Future/Task created at (most recent call last): z%s Úmessage)rrÚjoinrÚ format_listÚrstripr Úcall_exception_handler)rÚmsgÚsrcrrrÚ__del__csz_TracebackLogger.__del__N)r rrr) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__rrrr&rrrrr s 0r c@s¸eZdZdZeZdZdZdZdZ dZ dZ ddœdd„Z e jZdd„ZejrRd d „Zd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zejr´eZ dS)!ra,This class is *almost* compatible with concurrent.futures.Future. Differences: - This class is not thread-safe. - result() and exception() do not take a timeout argument and raise an exception when the future isn't done yet. - Callbacks registered with add_done_callback() are always called via the event loop's call_soon(). - This class is not compatible with the wait() and as_completed() methods in the concurrent.futures package. (In Python 3.4 or later we may be able to unify the implementations.) NF)r cCs@|dkrtjƒ|_n||_g|_|jjƒrú )rr'r Ú _repr_info)rrrrÚ__repr__¥szFuture.__repr__cCsD|js dS|j}d|jj||dœ}|jr4|j|d<|jj|ƒdS)Nz %s exception was never retrieved)rÚ exceptionrr)Ú_log_tracebackÚ _exceptionrr'rrr#)rrÚcontextrrrr&¬s zFuture.__del__cCs&d|_|jtkrdSt|_|jƒdS)záCancel the future and schedule callbacks. If the future is already done or cancelled, return False. Otherwise, change the future's state to cancelled, schedule the callbacks and return True. FT)r5Ú_stateÚ_PENDINGÚ _CANCELLEDÚ_schedule_callbacks)rrrrÚcancel¼s  z Future.cancelcCsD|jdd…}|sdSg|jdd…<x|D]}|jj||ƒq*WdS)zªInternal: Ask the event loop to call all callbacks. The callbacks are scheduled to be called as soon as possible. Also clears the callback list. N)r-rÚ call_soon)rZ callbacksÚcallbackrrrr;Ês  zFuture._schedule_callbackscCs |jtkS)z(Return True if the future was cancelled.)r8r:)rrrrÚ cancelledØszFuture.cancelledcCs |jtkS)z™Return True if the future is done. Done means either that a result / exception are available, or that the future was cancelled. )r8r9)rrrrÚdoneÞsz Future.donecCs<|jtkrt‚|jtkr tdƒ‚d|_|jdk r6|j‚|jS)aReturn the result this future represents. If the future has been cancelled, raises CancelledError. If the future's result isn't yet available, raises InvalidStateError. If the future is done and has an exception set, this exception is raised. zResult is not ready.FN)r8r:rÚ _FINISHEDrr5r6Ú_result)rrrrÚresultæs   z Future.resultcCs,|jtkrt‚|jtkr tdƒ‚d|_|jS)a&Return the exception that was set on this future. The exception (or None if no exception was set) is returned only if the future is done. If the future has been cancelled, raises CancelledError. If the future isn't done yet, raises InvalidStateError. zException is not set.F)r8r:rrArr5r6)rrrrr4ös   zFuture.exceptioncCs*|jtkr|jj||ƒn |jj|ƒdS)zøAdd a callback to be run when the future becomes done. The callback is called with a single argument - the future object. If the future is already done when this is called, the callback is scheduled with call_soon. N)r8r9rr=r-Úappend)rÚfnrrrÚadd_done_callbacks zFuture.add_done_callbackcs<‡fdd„|jDƒ}t|jƒt|ƒ}|r8||jdd…<|S)z}Remove all instances of a callback from the "call when done" list. Returns the number of callbacks removed. csg|]}|ˆkr|‘qSrr)Ú.0Úf)rErrú sz/Future.remove_done_callback..N)r-Úlen)rrEZfiltered_callbacksZ removed_countr)rErÚremove_done_callbacks zFuture.remove_done_callbackcCs4|jtkrtdj|j|ƒƒ‚||_t|_|jƒdS)z–Mark the future done and set its result. If the future is already done when this method is called, raises InvalidStateError. z{}: {!r}N)r8r9rÚformatrBrAr;)rrCrrrÚ set_result s  zFuture.set_resultcCs‚|jtkrtdj|j|ƒƒ‚t|tƒr,|ƒ}t|ƒtkr@tdƒ‚||_t |_|j ƒt j rbd|_ nt||ƒ|_|jj|jjƒdS)z˜Mark the future done and set an exception. If the future is already done when this method is called, raises InvalidStateError. z{}: {!r}zPStopIteration interacts badly with generators and cannot be raised into a FutureTN)r8r9rrLÚ isinstanceÚtypeÚ StopIterationÚ TypeErrorr6rAr;r ÚPY34r5r Z _tb_loggerrr=r)rr4rrrÚ set_exception,s    zFuture.set_exceptionccs,|jƒsd|_|V|jƒs$tdƒ‚|jƒS)NTz"yield from wasn't used with future)r@Ú_asyncio_future_blockingÚAssertionErrorrC)rrrrÚ__iter__Ds zFuture.__iter__)!r'r(r)r*r9r8rBr6rrrTr5rr Z_future_repr_infor2r3r rRr&r<r;r?r@rCr4rFrKrMrSrVZPY35Ú __await__rrrrrns4   cCs|jƒr dS|j|ƒdS)z?Helper setting the result only if the future was not cancelled.N)r?rM)ZfutrCrrrÚ_set_result_unless_cancelledSsrXcCsZ|jƒs t‚|jƒr|jƒ|jƒs(dS|jƒ}|dk rD|j|ƒn|jƒ}|j|ƒdS)z8Copy state from a future to a concurrent.futures.Future.N) r@rUr?r<Zset_running_or_notify_cancelr4rSrCrM)Ú concurrentÚsourcer4rCrrrÚ_set_concurrent_future_stateZs  r[cCsj|jƒs t‚|jƒrdS|jƒ s&t‚|jƒr8|jƒn.|jƒ}|dk rT|j|ƒn|jƒ}|j|ƒdS)zqInternal helper to copy state from another Future. The other Future may be a concurrent.futures.Future. N)r@rUr?r<r4rSrCrM)rZÚdestr4rCrrrÚ_copy_future_stateis   r]csªtˆƒ r"tˆtjjƒ r"tdƒ‚tˆƒ rDtˆtjjƒ rDtdƒ‚tˆƒrRˆjnd‰tˆƒrdˆjnd‰dd„‰‡‡‡fdd„}‡‡‡‡fdd „}ˆj|ƒˆj|ƒdS) aChain two futures so that when one completes, so does the other. The result (or exception) of source will be copied to destination. If destination is cancelled, source gets cancelled too. Compatible with both asyncio.Future and concurrent.futures.Future. z(A future is required for source argumentz-A future is required for destination argumentNcSs"t|ƒrt||ƒn t||ƒdS)N)rr]r[)rÚotherrrrÚ _set_states z!_chain_future.._set_statecs2|jƒr.ˆdksˆˆkr"ˆjƒn ˆjˆjƒdS)N)r?r<Úcall_soon_threadsafe)Ú destination)Ú dest_looprZÚ source_looprrÚ_call_check_cancel“s z)_chain_future.._call_check_cancelcsJˆjƒrˆdk rˆjƒrdSˆdks,ˆˆkr8ˆˆ|ƒnˆjˆˆ|ƒdS)N)r?Z is_closedr`)rZ)r_rbrarcrrÚ_call_set_statešs  z&_chain_future.._call_set_state)rrNrYÚfuturesrrQrrF)rZrardrer)r_rbrarZrcrÚ _chain_future}s   rg)r cCsNt|ƒr |St|tjjƒs(tdj|ƒƒ‚|dkr8tjƒ}|j ƒ}t ||ƒ|S)z&Wrap concurrent.futures.Future object.z/concurrent.futures.Future is expected, got {!r}N) rrNrYrfrrUrLr r,Z create_futurerg)rr Z new_futurerrrr§s  )r*Ú__all__Zconcurrent.futuresrYZloggingr/rrr r r rrrrr9r:rAÚDEBUGZ STACK_DEBUGr rZ _PyFuturerXr[r]rgrZ_asyncioÚ ImportErrorZ_CFuturerrrrÚs>     Pc*