Files
wg-backend-django/acer-env/lib/python3.10/site-packages/asgiref/__pycache__/sync.cpython-310.pyc

160 lines
12 KiB
Plaintext
Raw Normal View History

2022-11-30 15:58:16 +07:00
o
<00>Ԅc<D484>N<00> @s\ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
m Z m Z ddl mZmZmZmZmZddlmZddlmZdd<08>Zd ed
efd d <0C>ZGd d<0E>d<0E>ZGdd<10>d<10>ZGdd<12>d<12>ZeZe   dd ddededd
eedefgeffdd<19><05>Ze  dd edefdededd
efdd<19><05>Z   ddd<19>ZdS)<1E>N)<02>Future<72>ThreadPoolExecutor)<05>Any<6E>Callable<6C>Dict<63>Optional<61>overload<61>)<01>CurrentThreadExecutor)<01>Localc CsV|D]&}z|<01><00>|<00>|<01>kr|<01>|<00>|<01><01>Wqty(|<01>|<00>|<01><01>YqwdS<00>N)<03>get<65>set<65> LookupError)<02>context<78>cvar<61>r<00>_/home/infidel/Sync/Project/ocp-wg-backend/acer-env/lib/python3.10/site-packages/asgiref/sync.py<70>_restore_contexts<04> <02><04>r<00>func<6E>returncCsVtjdkr
t<02>|<00>St<04>|<00>r|j}t<04>|<00>st|tj <09>r&|j
}t|tj <09>st<02>|<00>S)N)<02><00>) <0B>sys<79> version_info<66>asyncio<69>iscoroutinefunction<6F>inspect<63>ismethod<6F>__func__<5F>
isinstance<EFBFBD> functools<6C>partialr)rrrr<00>_iscoroutinefunction_or_partials



<EFBFBD>  <0C>
r#c@s(eZdZdZdd<03>Zdd<05>Zdd<07>ZdS) <09>ThreadSensitiveContextaiAsync context manager to manage context for thread sensitive mode
This context manager controls which thread pool executor is used when in
thread sensitive mode. By default, a single thread pool executor is shared
within a process.
In Python 3.7+, the ThreadSensitiveContext() context manager may be used to
specify a thread pool per context.
This context manager is re-entrant, so only the outer-most call to
ThreadSensitiveContext will set the context.
Usage:
>>> import time
>>> async with ThreadSensitiveContext():
... await sync_to_async(time.sleep, 1)()
cCs
d|_dSr )<01>token<65><01>selfrrr<00>__init__@s
zThreadSensitiveContext.__init__c<00>s6<00>ztj<01><02>W|Stytj<01>|<00>|_Y|Swr )<06> SyncToAsync<6E>thread_sensitive_contextr rrr%r&rrr<00>
__aenter__Cs<02>  <0C><02>z!ThreadSensitiveContext.__aenter__c<00>s8<00>|jsdStj<02>|d<00>}|r|<04><04>tj<05>|j<00>dSr )r%r)<00>context_to_thread_executor<6F>pop<6F>shutdownr*<00>reset)r'<00>exc<78>value<75>tb<74>executorrrr<00> __aexit__Ks<02>z ThreadSensitiveContext.__aexit__N)<07>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__r(r+r4rrrrr$,s
 r$c@sZeZdZUdZiZded<e<06>ZiZded<ddd<08>Z d d
<EFBFBD>Z
d d <0C>Z d d<0E>Z dd<10>Z dS)<13> AsyncToSynca<63>
Utility class which turns an awaitable that only works on the thread with
the event loop into a synchronous callable that works in a subthread.
If the call stack contains an async loop, the code runs there.
Otherwise, the code runs in a new loop in a new thread.
Either way, this thread then pauses and waits to run any thread_sensitive
code called from further down the call stack using SyncToAsync, before
finally exiting once the async task returns.
z,Dict[asyncio.Task[object], threading.Thread]<5D>
launch_mapz6Dict[asyncio.AbstractEventLoop, CurrentThreadExecutor]<5D>loop_thread_executorsFcCs<>t|<01>rt|<01>stt|d|<01><03>stjddd<04>||_z|jj|_Wn ty*Ynw|r2d|_dSzt <09>
<EFBFBD>|_WdSt yatt j dd<00>}|r[|t<0E><0F>kr[tt j dd<00>|_YdSd|_YdSw)N<>__call__z4async_to_sync was passed a non-async-marked callable<6C>)<01>
stacklevel<EFBFBD>main_event_loop_pid<69>main_event_loop)<10>callabler#<00>getattr<74>warnings<67>warn<72> awaitable<6C>__self__<5F>AttributeErrorr@r<00>get_running_loop<6F> RuntimeErrorr)<00> threadlocal<61>os<6F>getpid)r'rE<00>force_new_loopr?rrrr(ms<<02>
<02><02><06> <02>
 <04> <0C> <02>zAsyncToSync.__init__c Os<>zt<00><01>}Wn tyYn w|<03><03>rtd<01><01>t<04><05>g}t<06>}t<07><08>}t |j
d<02>r/|j
j }nd}t <0C>}||j
_ d} zh|<00> ||||t<0E><0F>|<04>}
|jrO|j<10><03>sqt<00><11>} ||j| <tdd<04>} | <0B>|j| |
<EFBFBD>} |rl|<08>| <0C>| <0C><17>n|j<10>|jj|
<EFBFBD>|r<>|<08>|<05>W| dur<>|j| =t |j
d<02>r<>|j
` |r<>||j
_ t|d<00>|<05><17>S| dur<>|j| =t |j
d<02>r<>|j
` |r<>||j
_ t|d<00>w)NznYou cannot use AsyncToSync in the same thread as an async event loop - just await the async function directly.<2E>currentr <00><01> max_workersr)rrHrI<00>
is_running<EFBFBD> contextvars<72> copy_contextr<00> threading<6E>current_thread<61>hasattr<74> executorsrNr
<00> main_wrapr<00>exc_infor@<00>new_event_loopr;r<00>submit<69>_run_event_loop<6F>run_until_future<72>result<6C>call_soon_threadsafe<66> create_taskr) r'<00>args<67>kwargs<67>
event_loopr<00> call_result<6C> source_thread<61>old_current_executor<6F>current_executor<6F>looprE<00> loop_executor<6F> loop_futurerrrr<<00>sj  <02><04>
 
<04>

<04>

<04>
<02>  <08> zAsyncToSync.__call__cs<>t<00>|<01>zm|<01>|<02>Wz[t<00>|<01><01><00>D]}|<03><04>q<14>fdd<02>}|<01>|<04><00><00>D]}|<03><05>r0q)|<03><06>durA|<01>d|<03><06>|d<05><03>q)t|d<06>r[|<01>|<01> <09><00>W|<01>
<EFBFBD>t<00>|j <0B>dSW|<01>
<EFBFBD>t<00>|j <0B>dS|<01>
<EFBFBD>t<00>|j <0B>wzYt<00>|<01><01><00>D]}|<03><04>q{<7B>fdd<02>}|<01>|<04><00><00>D]}|<03><05>r<>q<EFBFBD>|<03><06>dur<>|<01>d|<03><06>|d<05><03>q<>t|d<06>r<>|<01>|<01> <09><00>W|<01>
<EFBFBD>t<00>|j <0B>wW|<01>
<EFBFBD>t<00>|j <0B>w|<01>
<EFBFBD>t<00>|j <0B>w)zP
Runs the given event loop (designed to be called in a thread).
c<00>s<00>tj<01>ddi<01>IdHdS)N<>return_exceptionsT)r<00>gatherr<00><01>tasksrrrl<00>s<02>z+AsyncToSync._run_event_loop.<locals>.gatherNz(unhandled exception during loop shutdown)<03>message<67> exception<6F>task<73>shutdown_asyncgens) r<00>set_event_loop<6F>run_until_complete<74> all_tasks<6B>cancel<65> cancelledrp<00>call_exception_handlerrVrr<00>closer@)r'rh<00>cororqrlrrmrr\<00>sn
 

   <04><04><02>
<02><08><02>

   <04><04><02>
<02><08>zAsyncToSync._run_event_loopcCst<00>|j|<01>}t<00>||j<04>S<00>z*
Include self for methods
)r!r"r<<00>update_wrapperrE)r'<00>parent<6E>objtyperrrr<00>__get__szAsyncToSync.__get__c
<00>s<00>|dur t|d<00>t<01><02>}||j|<zaz*|dr3z|d<00>ty2|j|i|<02><01>IdH}Yn w|j|i|<02><01>IdH}WntyV} z |<03>| <09>WYd} ~ nd} ~ ww|<03>|<08>W|j|=t<08> <09>|d<dSW|j|=t<08> <09>|d<dS|j|=t<08> <09>|d<w)zs
Wraps the awaitable with something that puts the result into the
result/exception future.
Nrr )
rr)<00>get_current_taskr:<00> BaseExceptionrE<00> set_exception<6F>
set_resultrRrS)
r'rarbrdrerYr<00> current_taskr^<00>errrrXs4<02> 
 <02><04><08><02> <02><08>zAsyncToSync.main_wrapN)F)r5r6r7r8r:<00>__annotations__r rWr;r(r<r\rrXrrrrr9Us
  
&I$ r9c @s<>eZdZUdZdejvre<06><07>Ze<08> e
e ejd<00>d<03><01>iZ de d<e<0E><0F>Ze
dd<03>Ze<12>d<07>Zde d<e<12>d <09>Zd
e d <e<16><17>Zd e d < ddedefdededddfdd<16>Zdd<18>Zdd<1A>Zdd<1C>Z e!dd<1E><00>Z"dS) r)a
Utility class which turns a synchronous callable into an awaitable that
runs in a threadpool. It also sets a threadlocal inside the thread so
calls to AsyncToSync can escape it.
If thread_sensitive is passed, the code will run in the same thread as any
outer code. This is needed for underlying Python code that is not
threadsafe (for example, code which handles SQLite database connections).
If the outermost program is async (i.e. SyncToAsync is outermost), then
this will be a dedicated single sub-thread that all sync code runs in,
one after the other. If the outermost program is sync (i.e. AsyncToSync is
outermost), this will just be the main thread. This is achieved by idling
with a CurrentThreadExecutor while AsyncToSync is blocking its sync parent,
rather than just blocking.
If executor is passed in, that will be used instead of the loop's default executor.
In order to pass in an executor, thread_sensitive must be set to False, otherwise
a TypeError will be raised.
<20> ASGI_THREADSrOz,Dict[threading.Thread, asyncio.Task[object]]r:r r*zcontextvars.ContextVar[str]<5D>deadlock_contextzcontextvars.ContextVar[bool]z5weakref.WeakKeyDictionary[object, ThreadPoolExecutor]r,TNr.<2E>thread_sensitiver3rrcCs<>t|<01>rt|<01>stt|d|<01><03>rtd<02><01>||_t<05>||<01>||_tj j
|_
|r/|dur/td<03><01>||_ z|j |_ WdSt yCYdSw)Nr<z4sync_to_async can only be applied to sync functions.z6executor must not be set when thread_sensitive is True)rAr#rB<00> TypeErrorrr!r|<00>_thread_sensitiver<00>
coroutines<EFBFBD> _is_coroutine<6E> _executorrFrG)r'rr<>r3rrrr(as&<02><02><02> 
  <02>zSyncToAsync.__init__c <00>sv<00>t<00><01>}|jr\ttjd<01>rtjj}nL|jr7|j<07>d<00>r7|j<07><08>}||j vr,|j |}n3t
dd<03>}||j |<n(|tj vrBtj |}n|j rO|j <0C>d<04>rOt d<05><01>|j}|j r[|j <0C>d<06>n|j}t<11><12>}tj|jg|<01>Ri|<02><01>}|j}|f}i}z3|<03>|tj|j||<00><19>t<1A><1B>|g|<01>Ri|<02><01><01>} tj| dd<07>IdH}
Wt|<06>|j r<>|j <0C>d<04>|
St|<06>|j r<>|j <0C>d<04>ww)NrNr rOFz9Single thread executor already being used, would deadlockT)<01>timeout)rrHr<>rVr9rWrNr*r r,rr;r<>rI<00>single_thread_executorrr<>rRrSr!r"r<00>run<75>run_in_executor<6F>thread_handlerr<72>rrY<00>wait_forr) r'rarbrhr3r*r<00>childr<00>future<72>retrrrr<ysj<02> 
 <04>

 
 
 <04> <02><02><06><04><04>  <08><02>zSyncToAsync.__call__cCst<00>|j|<01>Sr{)r!r"r<)r'r}r~rrrr<00>szSyncToAsync.__get__c Os<>||j_t<02><03>|j_t<05><06>}tj<08> |<02>|krd}n||j|<d}z0|drBz|d<00>t
yA||i|<06><01>YW|r@|j|=SSw||i|<06><01>W|rP|j|=SS|rW|j|=w)zE
Wraps the sync application with exception handling.
FTr ) rJr@rKrLr?rTrUr9r:r r<>) r'rh<00> source_taskrYrrarbrU<00>
parent_setrrrr<><00>s, 
 
<02><02>
<06>
zSyncToAsync.thread_handlercCs zt<00><01>WStyYdSw)zi
Implementation of asyncio.current_task()
that returns None if there is no task.
N)rr<>rIrrrrr<><00>s

 <02>zSyncToAsync.get_current_task<73>TN)#r5r6r7r8rK<00>environr<00>get_event_looprh<00>set_default_executorr<00>intr:r<>rT<00>localrJr<>rR<00>
ContextVarr*r<><00>weakref<65>WeakKeyDictionaryr,rr<00>boolrr(r<rr<><00> staticmethodr<64>rrrrr)'sD

<04> 
 <0C> <0C>
<EFBFBD><04>
<02><02><02>
<EFBFBD>C!r)Tr<54>r3r.cC<00>dSr r<00>rr<>r3rrr<00> sync_to_async<6E><00>r<>cCr<>r rr<>rrrr<><00>r<>cs$|dur <0B><00>fdd<02>St|<00><01>d<03>S)Ncst|<00><01>d<01>S)N<>r<>r3<00>r))<01>f<>r3r<>rr<00><lambda> s
<06>zsync_to_async.<locals>.<lambda>r<>r<>r<>rr<>rr<>s<06>)NTNr<4E>)r<00>asyncio.coroutinesrRr!rrKrrTrCr<><00>concurrent.futuresrr<00>typingrrrrr<00>current_thread_executorr
r<>r rr<>r#r$r9r)<00> async_to_syncr<63>rrrr<00><module>sf   )SJ<04><02><02><02> <0C><04>
<02><02><02> <0C> <0E>