
    MKi                    <   S SK Jr  S SKrS SKrS SKrS SKJrJrJ	r	  S SK
JrJrJr  S SKJr  S SKJr  S SKJrJrJr  S SKJr  S S	KJr  S S
KJr  S SKJrJr  S SKJ r   \" S5      r!\" S5      r" " S S\\!\"4   5      r# " S S\5      r$ " S S\5      r%SS jr&SS jr'g)    )annotationsN)	AwaitableCallable	Coroutine)AbstractAsyncContextManagerAbstractContextManager	ExitStack)copy_context)TracebackType)ProtocolTypeVarcast)RunnableConfig)get_executor_for_config)	ParamSpec)CONTEXT_NOT_SUPPORTEDrun_coroutine_threadsafe)GraphBubbleUpPTc                  J    \ rS rSrSSSSS.               SS jjrSrg)	Submit   NFT__name____cancel_on_exit____reraise_on_exit____next_tick__c                   g N )selffnr   r   r   r   argskwargss           \/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langgraph/pregel/_executor.py__call__Submit.__call__   s     (+    r!   r#   Callable[P, T]r$   P.argsr   
str | Noner   boolr   r.   r   r.   r%   P.kwargsreturnzconcurrent.futures.Future[T])r   
__module____qualname____firstlineno__r'   __static_attributes__r!   r)   r&   r   r      sh    
  $#($(#	+	+ 	+ 		+
 !	+ "	+ 	+ 	+ 
&	+ 	+r)   r   c                      \ rS rSrSrSS jrSSSSS.               SS jjrSS	 jrSS
 jr        SS jr	Sr
g)BackgroundExecutor(   a5  A context manager that runs sync tasks in the background.
Uses a thread pool executor to delegate tasks to separate threads.
On exit,
- cancels any (not yet started) tasks with `__cancel_on_exit__=True`
- waits for all tasks to finish
- re-raises the first exception from tasks with `__reraise_on_exit__=True`c                    [        5       U l        U R                  R                  [        U5      5      U l        0 U l        g r    )r	   stackenter_contextr   executortasks)r"   configs     r&   __init__BackgroundExecutor.__init__0   s.    [


001H1PQIK
r)   NFTr   c                  [        5       nU(       aZ  [        [        R                  R                  [
           U R                  R                  " [        UR                  U/UQ70 UD65      n	O+U R                  R                  " UR                  U/UQ70 UD6n	X44U R                  U	'   U	R                  U R                  5        U	$ r    )r
   r   
concurrentfuturesFuturer   r;   submit	next_tickrunr<   add_done_callbackdone)
r"   r#   r   r   r   r   r$   r%   ctxtasks
             r&   rD   BackgroundExecutor.submit6   s     n""))!,$$YMdMfMD
 ==''EdEfED.D

4tyy)r)   c                     UR                  5         U R                  R                  U5        g! [         a    U R                  R                  U5         g[         a     gf = f)z3Remove the task from the tasks dict when it's done.N)resultr<   popr   BaseException)r"   rJ   s     r&   rH   BackgroundExecutor.doneM   sP    		!KKM JJNN4   	! JJNN4  		s   . %A!	A! A!c                    U R                   $ r    rD   r"   s    r&   	__enter__BackgroundExecutor.__enter__Z   s    {{r)   c                @   U R                   R                  5       nUR                  5        H!  u  nu  pgU(       d  M  UR                  5         M#     U Vs1 s H  oR	                  5       (       a  M  UiM     sn=n	(       a  [
        R                  R                  U	5        U R                  R                  XU5        Uc7  UR                  5        H"  u  nu  pzU
(       d  M   UR                  5         M$     g g s  snf ! [
        R                  R                   a     MN  f = fr    )r<   copyitemscancelrH   rA   rB   waitr9   __exit__rM   CancelledError)r"   exc_type	exc_value	tracebackr<   rJ   rY   _tpendingreraises              r&   r[   BackgroundExecutor.__exit__]   s     

!!&D+6v "/ #(8%Qvvxq%8878##G,

H;&+kkm"lqKKM	 '4  9 "))88 s   C60C6 C;;DD)r;   r9   r<   r=   r   r0   Noner*   )rJ   zconcurrent.futures.Futurer0   rf   r0   r   )r]   type[BaseException] | Noner^   BaseException | Noner_   TracebackType | Noner0   zbool | None)r   r1   r2   r3   __doc__r>   rD   rH   rT   r[   r4   r!   r)   r&   r6   r6   (   s    RL  $#($(#  	
 ! "   
&.!, ( (	
 
r)   r6   c                      \ rS rSrSrSS jrSSSSS.               SS jjrSS	 jrSS
 jr        SS jr	Sr
g)AsyncBackgroundExecutorz   a;  A context manager that runs async tasks in the background.
Uses the current event loop to delegate tasks to asyncio tasks.
On exit,
- cancels any tasks with `__cancel_on_exit__=True`
- waits for all tasks to finish
- re-raises the first exception from tasks with `__reraise_on_exit__=True`
  ignoring CancelledErrorc                    0 U l         [        5       U l        [        R                  " 5       U l        UR                  S5      =n(       a  [        R                  " U5      U l        g S U l        g )Nmax_concurrency)	r<   objectsentinelasyncioget_running_looploopget	Semaphore	semaphore)r"   r=   rp   s      r&   r>    AsyncBackgroundExecutor.__init__   sU    >@
,,.	$jj):;;?;7>7H7H8DN "DNr)   NFTr   c               h   [        [        S S [        4   U" U0 UD65      nU R                  (       a  [	        U R                  U5      n[
        (       a  [        XR                  X%S9n	O[        UU R                  U[        5       US9n	X44U R                  U	'   U	R                  U R                  5        U	$ )N)namelazy)r{   contextr|   )r   r   r   rx   gatedr   r   ru   r
   r<   rG   rH   )
r"   r#   r   r   r   r   r$   r%   cororJ   s
             r&   rD   AsyncBackgroundExecutor.submit   s     IdD!m,b$.A&.AB>>.D  +iihD ,		$"D /D

4tyy)r)   c                8    UR                  5       =n(       a2  [        U[        5      (       a  U R                  R	                  U5        g g U R                  R	                  U5        g ! [
        R                   a    U R                  R	                  U5         g f = fr    )	exception
isinstancer   r<   rN   rs   r\   )r"   rJ   excs      r&   rH   AsyncBackgroundExecutor.done   st    		!nn&&s& c=11JJNN4( 2 

t$%% 	!JJNN4 	!s   AA' A' '/BBc                "   #    U R                   $ 7fr    rR   rS   s    r&   
__aenter__"AsyncBackgroundExecutor.__aenter__   s     {{s   c                  #    U R                   R                  5       nUR                  5        H,  u  nu  pgU(       d  M  UR                  U R                  5        M.     U(       a  [
        R                  " U5      I S h  vN   Uc@  UR                  5        H+  u  nu  pxU(       d  M   UR                  5       =n	(       a  U	eM-     g g  NH! [
        R                   a     MJ  f = f7fr    )	r<   rW   rX   rY   rr   rs   rZ   r   r\   )
r"   r]   r^   r_   r<   rJ   rY   r`   rc   r   s
             r&   	__aexit__!AsyncBackgroundExecutor.__aexit__   s      

!!&D+6vDMM* "/ ,,u%%%&+kkm"lq"nn..s.!	 /	 '4  & -- s:   8C#?C#=C>(C#'C C#C C#C  C#)ru   rx   rr   r<   re   )r#   zCallable[P, Awaitable[T]]r$   r,   r   r-   r   r.   r   r.   r   r.   r%   r/   r0   zasyncio.Future[T])rJ   zasyncio.Futurer0   rf   rg   )r]   rh   r^   ri   r_   rj   r0   rf   )r   r1   r2   r3   rk   r>   rD   rH   r   r   r4   r!   r)   r&   rm   rm   z   s    !	"  $#($(#%  	
 ! "   
:
!, ( (	
 
r)   rm   c                   #    U  ISh  vN   UI Sh  vN sSSS5      ISh  vN   $  N N N	! , ISh  vN  (       d  f       g= f7f)zHA coroutine that waits for a semaphore before running another coroutine.Nr!   )rx   r   s     r&   r~   r~      s&     yz yy yyysE   A	)A	/+/A	-A	/A	A8AA	c                >    [         R                  " S5        U " U0 UD6$ )zPA function that yields control to other threads before running another function.r   )timesleep)r#   r$   r%   s      r&   rE   rE      s    JJqMtvr)   )rx   zasyncio.Semaphorer   zCoroutine[None, None, T]r0   r   )r#   r+   r$   r,   r%   r/   r0   r   )(
__future__r   rs   concurrent.futuresrA   r   collections.abcr   r   r   
contextlibr   r   r	   contextvarsr
   typesr   typingr   r   r   langchain_core.runnablesr   langchain_core.runnables.configr   typing_extensionsr   langgraph._internal._futurer   r   langgraph.errorsr   r   r   r   r6   rm   r~   rE   r!   r)   r&   <module>r      s    "    : : U U $   4 C ' W *cNCL
+Xad^ 
+O/ OdY9 Yxr)   