f"dZdZddlmZddlZddlZddlZddlZddlZddl Z ejZ da ejZdZej eee dr3e j$ej&ej(ej*Gd d Zd ZGd d ej0ZGddej4Zy)zImplements ThreadPoolExecutor.z"Brian Quinlan (brian@sweetapp.com))_baseNFct5dadddttj }|D]\}}|j d|D]\}}|j y#1swY\xYwNT)_global_shutdown_lock _shutdownlist_threads_queuesitemsputjoin)r tqs 0/usr/lib/python3.12/concurrent/futures/thread.py _python_exitrsl   &&( )E1 d 1  s A%%A.register_at_fork)beforeafter_in_childafter_in_parentc<eZdZdZdZeejZy) _WorkItemc<||_||_||_||_yN)futurefnargskwargs)selfrrrrs r__init__z_WorkItem.__init__/s   c$|jjsy |j|ji|j}|jj |y#t $r'}|jj|d}Yd}~yd}~wwxYwr)rset_running_or_notify_cancelrrr set_result BaseException set_exception)rresultexcs rrunz _WorkItem.run5st{{779  +TWWdii74;;7F KK " "6 *   KK % %c *D s&A B(B  BN) __name__ __module__ __qualname__rr' classmethodtypes GenericAlias__class_getitem__rrrr.s +$E$6$67rrc`| || |j }||j~&|}ts| |jr|d|_ |jdy~]#t$r=tjjdd|}||j YywxYw#t j$r9|}||jj~|jd}YwxYw#t$r$tjjddYywxYw)NzException in initializer:T)exc_info)blockzException in worker)r#rLOGGERcritical_initializer_failed get_nowaitqueueEmpty_idle_semaphorereleasegetr'rr )executor_reference work_queue initializerinitargsexecutor work_items r_workerrBEs@   "!D 7&113 $ )+H H,0B0B')-H&t$=  LL ! !"= ! M)+H#,,.   ;; 7-/',,446&NNN6  78 D 3dCDsMA(DB1A D&D(AB.-B.1A C=:D<C==D*D-,D-ceZdZdZy)BrokenThreadPoolzR Raised when a worker thread in a ThreadPoolExecutor failed initializing. N)r(r)r*__doc__r/rrrDrDssrrDceZdZejj Z d dZdZe jjje_ dZ dZ d dddZe jjje_ y) ThreadPoolExecutorNc|%tdtjxsddz}|dkr td|t |s t d||_tj|_ tjd|_ t|_d|_d|_tj"|_|xsd |j'z|_||_||_y) aInitializes 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 rz"max_workers must be greater than 0zinitializer must be a callableFzThreadPoolExecutor-%d)minos cpu_count ValueErrorcallable TypeError _max_workersr7 SimpleQueue _work_queue threading Semaphorer9set_threads_brokenrLock_shutdown_lock_counter_thread_name_prefix _initializer _initargs)r max_workersthread_name_prefixr>r?s rrzThreadPoolExecutor.__init__~s  b2<<>#6Q!";.weakref_cbs EE$Krz%s_%d)nametargetr)r9acquirerTlenrXrRr]rUThreadrBweakrefrefr^r_startaddr )rrm num_threads thread_namer s rrez'ThreadPoolExecutor._adjust_thread_counts    ' ' ' 2 !,, $--( ** *!T%=%=%E%0%22K  k''.{{4'D'+'7'7'+'8'8'+~~'78A GGI MM  a !%!1!1OA  +rc"|j5d|_ |jj}|.|j jt|jL#tj $rYnwxYw dddy#1swYyxYw)NzBA thread initializer failed, the thread pool is not usable anymore) r[rYrTr6r7r8rr$rD)rrAs rr5z&ThreadPoolExecutor._initializer_faileds  S4DL $ 0 0 ; ; =I($$223CDLL3QR {{ S S Ss- BA"1B"A85B7A88BBF)cancel_futurescz|j5d|_|r9 |jj}||j j8|jjdddd|r"|jD]}|jyy#tj $rY]wxYw#1swYGxYwr) r[rrTr6r7r8rcancelr rXr )rwaitrzrAr s rshutdownzThreadPoolExecutor.shutdowns   '!DN$($4$4$?$?$A !,!((//1      & ' ]]   !;; ' 's- B1B8B1B.+B1-B..B11B:)NNr/)T)r(r)r* itertoolscount__next__r\rrhrExecutorrErer5r~r/rrrGrGyssy ))H<>,.$"L"^^**22FN2. SE(~~..66HrrG)rE __author__concurrent.futuresrrr7rUr,rsrMWeakKeyDictionaryr rrZrr_register_atexithasattrrrp_at_fork_reinitr:rrBBrokenExecutorrDrrGr/rrrs% 1 $   ,'++-  ' ( <( 2!"B4<<'<'L'L(=(E(EG 88.+D\u++ v7v7r