)L i ddlmZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZgdZe dZdd d d Z d dd Zdd Zy)) annotationsN)get_running_loop) TracebackType)Any AwaitableCallableTypeVarcast)run_in_executor_with_contextcall_soon_threadsafeget_traceback_from_context_T)loopc|xs t}tj}|jd|j|g|S)z Run a function in an executor, but make sure it uses the same contextvars. This is required so that the function will see the right application. See also: https://bugs.python.org/issue34014 N)r contextvars copy_contextrun_in_executorrun)funcrargsctxs d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/eventloop/utils.pyr r s@  %#%D*779C 4  cggt ;d ;;c|xs t|jytj|zdfd jy)a Wrapper around asyncio's `call_soon_threadsafe`. This takes a `max_postpone_time` which can be used to tune the urgency of the method. Asyncio runs tasks in first-in-first-out. However, this is not what we want for the render function of the prompt_toolkit UI. Rendering is expensive, but since the UI is invalidated very often, in some situations we render the UI too often, so much that the rendering CPU usage slows down the rest of the processing of the application. (Pymux is an example where we have to balance the CPU time spend on rendering the UI, and parsing process output.) However, we want to set a deadline value, for when the rendering should happen. (The UI should stay responsive). NctdgsytjkDryjy)N_ready)getattrtimer )rloop2max_postpone_untilschedulesrr!z&call_soon_threadsafe..scheduleCsB uh+ F  99;+ + F  ""8,r)returnNone)rr r)rmax_postpone_timerrr r!s` @@@rr r %sX*  &$&E  ""4('88--" x(rc|jd}|r=t|drtt|jSt j dSy)z4 Get the traceback object from the context. exception __traceback__N)gethasattrr rr'sysexc_info)contextr&s rr r WsH K(I 9o . y'>'>? ? <<>!$ $ r)rzCallable[..., _T]rrr asyncio.AbstractEventLoop | Noner"z Awaitable[_T])NN)rzCallable[[], None]r$z float | Nonerr.r"r#)r-zdict[str, Any]r"zTracebackType | None) __future__rasynciorr+rrtypesrtypingrrrr r __all__rr r r rrr5s" $::   T] .2< < < +< <&'+-1/) /)#/) +/) /)dr