
    F\h#                        S r SrSSKJr  SSKrSSKrSSKrSSKrSSKrSSK	r	\R                  " 5       rSq\R                  " 5       rS r\R                   " \5        \" \	S5      (       aJ  \	R$                  " \R&                  \R(                  \R*                  S9  \	R$                  " \R,                  S	9   " S
 S5      rS r " S S\R2                  5      r " S S\R6                  5      rg)zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com)    )_baseNFc                      [            SqS S S 5        [        [        R	                  5       5      n U  H  u  pUR                  S 5        M     U  H  u  pUR                  5         M     g ! , (       d  f       Nc= fNT)_global_shutdown_lock	_shutdownlist_threads_queuesitemsputjoin)r
   tqs      0/usr/lib/python3.13/concurrent/futures/thread.py_python_exitr      sW    		 
&&()E	d 	  
	s   A''
A5register_at_fork)beforeafter_in_childafter_in_parent)r   c                   D    \ rS rSrS rS r\" \R                  5      r	Sr
g)	_WorkItem/   c                 4    Xl         X l        X0l        X@l        g N)futurefnargskwargs)selfr   r   r   r   s        r   __init___WorkItem.__init__0   s    	    c                 0   U R                   R                  5       (       d  g  U R                  " U R                  0 U R                  D6nU R                   R                  U5        g ! [         a'  nU R                   R                  U5        S n  S nAg S nAff = fr   )r   set_running_or_notify_cancelr   r   r   
set_resultBaseExceptionset_exception)r   resultexcs      r   run_WorkItem.run6   su    {{7799	+WWdii74;;7F KK""6*  	KK%%c*D	s   &A$ $
B.BB)r   r   r   r   N)__name__
__module____qualname____firstlineno__r   r)   classmethodtypesGenericAlias__class_getitem____static_attributes__ r!   r   r   r   /   s    + $E$6$67r!   r   c                 x   Ub   U" U6      UR                  5       nUb  UR                  5         AM(  U " 5       n[        (       d  Ub  UR                  (       a  Ub  SUl        UR                  S 5        g AMl  ! [          a;    [        R                  R                  SSS9  U " 5       nUb  UR	                  5          g f = f! [        R                   a7    U " 5       nUb  UR                  R                  5         AUR                  SS9n Nf = f! [          a!    [        R                  R                  SSS9   g f = f)NzException in initializer:T)exc_info)blockzException in worker)r%   r   LOGGERcritical_initializer_failed
get_nowaitqueueEmpty_idle_semaphorereleasegetr)   r   r   )executor_reference
work_queueinitializerinitargsexecutor	work_items         r   _workerrG   F   sB   	"!D7&113	 $)+H
 yH,0B0B ')-H&t$=   	LL!!"=!M)+H#,,.	 ;; 7-/',,446&NNN6	78  D3dCDsM   A8 D C  AD 5D 8AB=<B= ADD 
DD (D98D9c                       \ rS rSrSrSrg)BrokenThreadPoolt   zJ
Raised when a worker thread in a ThreadPoolExecutor failed initializing.
r4   N)r+   r,   r-   r.   __doc__r3   r4   r!   r   rI   rI   t   s    r!   rI   c                      \ rS rSr\R
                  " 5       R                  r  SS jrS r	\
R                  R                  R                  \	l        S rS rSSS.S	 jjr\
R                  R                  R                  \l        S
rg)ThreadPoolExecutorz   Nc                    Uc+  [        S[        R                  " 5       =(       d    SS-   5      nUS::  a  [        S5      eUb  [	        U5      (       d  [        S5      eXl        [        R                  " 5       U l	        [        R                  " S5      U l        [        5       U l        SU l        SU l        [        R"                  " 5       U l        U=(       d    S	U R'                  5       -  U l        X0l        X@l        g)
a]  Initializes a new ThreadPoolExecutor instance.

Args:
    max_workers: The maximum number of threads that can be used to
        execute the given calls.
    thread_name_prefix: An optional name prefix to give our threads.
    initializer: A callable used to initialize worker threads.
    initargs: A tuple of arguments to pass to the initializer.
N          r   z"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)minosprocess_cpu_count
ValueErrorcallable	TypeError_max_workersr<   SimpleQueue_work_queue	threading	Semaphorer>   set_threads_brokenr   Lock_shutdown_lock_counter_thread_name_prefix_initializer	_initargs)r   max_workersthread_name_prefixrC   rD   s        r   r   ThreadPoolExecutor.__init__   s      b2#7#7#9#>Q!"CDK!ABB"8K+@+@<==' ,,.(2215'nn.$6 %P%<t}}%N 	 '!r!   c                   U R                      [           U R                  (       a  [        U R                  5      eU R                  (       a  [        S5      e[        (       a  [        S5      e[        R                  " 5       n[        XAX#5      nU R                  R                  U5        U R                  5         UsS S S 5        sS S S 5        $ ! , (       d  f       O= fS S S 5        g ! , (       d  f       g = f)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)rb   r   r`   rI   r   RuntimeErrorr   Futurer   r[   r   _adjust_thread_count)r   r   r   r   fws         r   submitThreadPoolExecutor.submit   s      "7||&t||44~~"#OPPy" $: ; ; A!.A  #%%' #8"7  "7"7   s#   C'B&C:	C'
C	C''
C5c                    U R                   R                  SS9(       a  g U R                  4S jn[        U R                  5      nX R
                  :  a  SU R                  =(       d    U U4-  n[        R                  " U[        [        R                  " X5      U R                  U R                  U R                  4S9nUR                  5         U R                  R                  U5        U R                  [         U'   g g )Nr   )timeoutc                 &    UR                  S 5        g r   )r   )_r   s     r   
weakref_cb;ThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cb   s    EE$Kr!   z%s_%d)nametargetr   )r>   acquirer[   lenr_   rY   rd   r\   ThreadrG   weakrefrefre   rf   startaddr	   )r   rv   num_threadsthread_namer   s        r   rm   'ThreadPoolExecutor._adjust_thread_count   s    '''2 !,, 	 $--(***!T%=%=%E%0%2 2K  k''.{{4'D'+'7'7'+'8'8'+~~'78A
 GGIMMa !%!1!1OA +r!   c                 0   U R                      SU l          U R                  R                  5       nUb.  UR                  R                  [        U R                  5      5        MN  ! [        R
                   a     Of = fS S S 5        g ! , (       d  f       g = f)NzBA thread initializer failed, the thread pool is not usable anymore)	rb   r`   r[   r;   r<   r=   r   r&   rI   )r   rF   s     r   r:   &ThreadPoolExecutor._initializer_failed   s      4DL  $ 0 0 ; ; =I ($$223CDLL3QR  {{  !  s-   	BA$3B$A;8B:A;;B
BF)cancel_futuresc                   U R                      SU l        U(       a;    U R                  R                  5       nUb  UR                  R                  5         M:  U R                  R                  S 5        S S S 5        U(       a$  U R                   H  nUR                  5         M     g g ! [        R
                   a     Mf  f = f! , (       d  f       NU= fr   )rb   r   r[   r;   r<   r=   r   cancelr   r_   r   )r   waitr   rF   r   s        r   shutdownThreadPoolExecutor.shutdown   s      !DN $($4$4$?$?$A	 !,!((//1    & !  ]] #  !;;  ! s-   CB&:C&B>:C=B>>C
C)
r`   r>   rf   re   rY   r   rb   rd   r_   r[   )N Nr4   )T)r+   r,   r-   r.   	itertoolscount__next__rc   r   rp   r   ExecutorrK   rm   r:   r   r3   r4   r!   r   rM   rM   z   sq      ))H<>,.$"L" ^^**22FN2.SE ( ~~..66Hr!   rM   )rK   
__author__concurrent.futuresr   r   r<   r\   r0   r}   rT   WeakKeyDictionaryr	   r   ra   r   r   _register_atexithasattrr   rz   _at_fork_reinitr?   clearr   rG   BrokenExecutorrI   r   rM   r4   r!   r   <module>r      s    %1
 $      	 ++-	 "(  
  < ( 2!""4<<'<'L'L(=(E(EG '<'<=8 8.+D\u++ v7 v7r!   