
    Mh                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZmZmZmZ g dZ ed          ZddddZ	 	 dddZddZdS )    )annotationsN)get_running_loop)TracebackType)Any	AwaitableCallableTypeVarcast)run_in_executor_with_contextcall_soon_threadsafeget_traceback_from_context_T)loopfuncCallable[..., _T]argsr   r    asyncio.AbstractEventLoop | NonereturnAwaitable[_T]c               r    |pt                      }t          j                    } |j        d|j        | g|R  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_contextrun_in_executorrun)r   r   r   ctxs       ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/eventloop/utils.pyr   r      sD     %#%%D*799C4cgt;d;;;;    Callable[[], None]max_postpone_timefloat | NoneNonec                     |pt                      |                                dS t          j                    |z   d fd                               dS )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).
    Nr   r!   c                     t          dg           s               d S t          j                    k    r               d S                                d S )N_ready)getattrtimer   )r   loop2max_postpone_untilschedules   r   r)   z&call_soon_threadsafe.<locals>.scheduleC   si    
 uh++ 	DFFFF 9;;+++DFFFF 	""8,,,,,r   )r   r!   )r   r   r&   )r   r   r   r'   r(   r)   s   `  @@@r   r   r   %   s    * &$&&E  ""4((('88- - - - - - - - -" 
x(((((r   contextdict[str, Any]TracebackType | Nonec                    |                      d          }|rCt          |d          rt          t          |j                  S t          j                    d         S dS )z4
    Get the traceback object from the context.
    	exception__traceback__   N)gethasattrr
   r   r/   sysexc_info)r*   r.   s     r   r   r   W   sZ     K((I %9o.. 	%y'>???
 <>>!$$4r   )r   r   r   r   r   r   r   r   )NN)r   r   r   r    r   r   r   r!   )r*   r+   r   r,   )
__future__r   asyncior   r3   r&   r   typesr   typingr   r   r   r	   r
   __all__r   r   r   r    r   r   <module>r;      s   " " " " " "      



  $ $ $ $ $ $       : : : : : : : : : : : : : :   WT]] .2< < < < < <& '+-1/) /) /) /) /)d     r   