+
   Jl                       ^ RI t ^ RIt^ RIt^RI5 RR.tRt ! R R]4      t ! R R]4      t	 ! R R	4      t
 ! R
 R4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )    N)*PoolTimeoutErrorzp
Standard Python Pool implementation based on Python API
for Intel(R) oneAPI Threading Building Blocks (oneTBB)
c                       ] tR t^OtRtRtR# )r   z>Raised when a result is not available within the given timeout N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       .build/lib/python3.14/site-packages/tbb/pool.pyr   r   O   s    Hr   c                      a  ] tR t^Tt o RtRR ltR]! 4       3R ltRR ltRR lt	RR lt
R]! 4       R3R ltRR	 ltRR
 ltRR ltR tR tR tR tR tR tR tRtV tR# )r   z
The Pool class provides standard multiprocessing.Pool interface
which is mapped onto oneTBB tasks executing in its thread pool
c                `    RV n         \        4       V n        R.\        4       ,          V n        R# )zv
:param nworkers (integer) number of worker threads to start
:param name (string) prefix for the worker threads' name
FN)_closed
task_group_tasksdefault_num_threads_pool)selfnworkersnames   &&&r   __init__Pool.__init__Z   s&    
  lW022
r   c                B    V P                  WV4      P                  4       # )zOEquivalent of the apply() builtin function. It blocks till
the result is ready.)apply_asyncget)r   funcargskwdss   &&&&r   apply
Pool.applyc   s      D15577r   Nc                B    V P                  WV4      P                  4       # )a,  A parallel equivalent of the map() builtin function. It
blocks till the result is ready.

This method chops the iterable into a number of chunks which
it submits to the process pool as separate tasks. The
(approximate) size of these chunks can be specified by setting
chunksize to a positive integer.)	map_asyncr   )r   r   iterable	chunksizes   &&&&r   mapPool.maph   s     ~~di8<<>>r   c                T    \        RR7      pV P                  WW44       \        V4      # )a  
An equivalent of itertools.imap().

The chunksize argument is the same as the one used by the
map() method. For very long iterables using a large value for
chunksize can make the job complete much faster than
using the default value of 1.

Also if chunksize is 1 then the next() method of the iterator
returned by the imap() method has an optional timeout
parameter: next(timeout) will raise processing.TimeoutError if
the result cannot be returned within timeout seconds.
Tas_iterator)OrderedResultCollector_create_sequencesiterr   r   r&   r'   	collectors   &&&& r   imap	Pool.imapr   s(     +t<	tyDIr   c                P    \        4       pV P                  WW44       \        V4      # )zThe same as imap() except that the ordering of the results
from the returned iterator should be considered
arbitrary. (Only when there is only one worker process is the
order guaranteed to be "correct".))UnorderedResultCollectorr.   r/   r0   s   &&&& r   imap_unorderedPool.imap_unordered   s&    
 -.	tyDIr   c                    V P                   '       d   Q h\        VR7      p\        WW54      pV P                  P	                  V4       V# )a[  A variant of the apply() method which returns an
ApplyResult object.

If callback is specified then it should be a callable which
accepts a single argument. When the result becomes ready,
callback is applied to it (unless the call failed). callback
should complete immediately since otherwise the thread which
handles the results will get blocked.callback)r   ApplyResultJobr   run)r   r   r    r!   r:   apply_resultjobs   &&&&&  r   r   Pool.apply_async   s?     <<<"H5$d1r   c                    \        VR7      p\        VRR7      pV P                  WW64      '       g   VP                  . 4       V# )aW  A variant of the map() method which returns a ApplyResult
object.

If callback is specified then it should be a callable which
accepts a single argument. When the result becomes ready
callback is applied to it (unless the call failed). callback
should complete immediately since otherwise the thread which
handles the results will get blocked.r9   Fr+   )r;   r-   r.   
_set_valuer   r   r&   r'   r:   r>   r1   s   &&&&&  r   r%   Pool.map_async   sA     #H5-lN	%%diKK

!
!"
%r   c                    \        VR7      p\        VRR7      pV P                  WW64      '       g   VP                  \	        . 4      4       V# )a  A variant of the imap() method which returns an ApplyResult
object that provides an iterator (next method(timeout)
available).

If callback is specified then it should be a callable which
accepts a single argument. When the resulting iterator becomes
ready, callback is applied to it (unless the call
failed). callback should complete immediately since otherwise
the thread which handles the results will get blocked.r9   Tr+   )r;   r-   r.   rB   r/   rC   s   &&&&&  r   
imap_asyncPool.imap_async   sE     #H5-lM	%%diKK

!
!$r(
+r   c                    \        VR7      p\        V4      pV P                  WW64      '       g   VP                  \	        . 4      4       V# )a  A variant of the imap_unordered() method which returns an
ApplyResult object that provides an iterator (next
method(timeout) available).

If callback is specified then it should be a callable which
accepts a single argument. When the resulting iterator becomes
ready, callback is applied to it (unless the call
failed). callback should complete immediately since otherwise
the thread which handles the results will get blocked.r9   )r;   r5   r.   rB   r/   rC   s   &&&&&  r   imap_unordered_asyncPool.imap_unordered_async   sC     #H5/=	%%diKK

!
!$r(
+r   c                    RV n         R# )zPrevents any more tasks from being submitted to the
pool. Once all the tasks have been completed the worker
processes will exit.TN)r   r   s   &r   close
Pool.close   s    
 r   c                Z    V P                  4        V P                  P                  4        R# )zStops the worker processes immediately without completing
outstanding work. When the pool object is garbage collected
terminate() will be called immediately.N)rM   r   cancelrL   s   &r   	terminatePool.terminate   s     	

r   c                :    V P                   P                  4        R# )z`Wait for the worker processes to exit. One must call
close() or terminate() before using join().N)r   waitrL   s   &r   join	Pool.join   s     	r   c                    V # Nr   rL   s   &r   	__enter__Pool.__enter__       r   c                &    V P                  4        R # rX   )rU   )r   exc_type	exc_value	tracebacks   &&&&r   __exit__Pool.__exit__   s    		r   c                F    V P                  4        V P                  4        R # rX   )rQ   rU   rL   s   &r   __del__Pool.__del__   s    		r   c                   V P                   '       d   Q h\        V4      pRp. pV'       g{   . p\        T;'       g    ^4       F9  p	 \        V4      p
\        T4      p\        Y3/ T4      pTP                  T4       K;  	  V'       g   Kf  VP                  \        V4      4       K  V F  pV P                  P                  V4       K   	  V#   \         d    Rp  K]  i ; i)ap  
Create callable objects to process and pushes them on the
work queue. Each work unit is meant to process a slice of
iterable of size chunksize. If collector is specified, then
the ApplyResult objects associated with the jobs will notify
collector when their result becomes ready.

eturn the list callable objects (basically: JobSequences)
pushed onto the work queue
FT)r   r/   rangenextStopIterationr;   r<   appendJobSequencer   r=   )r   r   r&   r'   r1   it_	exit_loop	sequencesseq_argr>   r?   ts   &&&&&         r   r.   Pool._create_sequences   s     <<<8n		C9>>*s)C  +95$L9

3 + s  S!12AKKOOA  %  $Is   CCC)r   r   r   )r   r   r   rX   )   NN)r   r	   r
   r   r   r   dictr"   r(   r2   r6   r   r%   rF   rI   rM   rQ   rU   rY   r`   rc   r.   r   __classdictcell____classdict__s   @r   r   r   T   ss     
3  " 8
?$ &(dft  "
 r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )r<   i
  zBA work unit that corresponds to the execution of a single functionc                6    Wn         W n        W0n        W@n        R# )z
:param func/args/kwds used to call the function
:param apply_result ApplyResult object that holds the result
of the function call
N)_func_args_kwds_result)r   r   r    r!   r>   s   &&&&&r   r   Job.__init__  s     


#r   c                     V P                   ! V P                  / V P                  B pV P                  P	                  V4       R#    T P                  P                  4         R# ; i)z
Call the function with the args/kwds and tell the ApplyResult
that its result is ready. Correctly handles the exceptions
happening during the execution of the function
N)r{   r|   r}   r~   rB   _set_exception)r   results   & r   __call__Job.__call__  sM    	,ZZ:tzz:F LL##F+	*LL'')s   &A A$)r|   r{   r}   r~   N	r   r	   r
   r   r   r   r   r   rv   rw   s   @r   r<   r<   
  s     L	$, ,r   r<   c                   0   a  ] tR tRt o RtR tR tRtV tR# )rj   i&  zVA work unit that corresponds to the processing of a continuous
sequence of Job objectsc                    Wn         R # rX   _jobs)r   jobss   &&r   r   JobSequence.__init__*  s    
r   c                :    V P                    F
  pV! 4        K  	  R# )z3
Call all the Job objects that have been specified
Nr   )r   r?   s   & r   r   JobSequence.__call__-  s     ::CE r   r   Nr   rw   s   @r   rj   rj   &  s      r   rj   c                   Z   a  ] tR tRt o RtRR ltRR ltRR ltR tR t	R	 t
R
 tRtV tR# )r;   i5  aE  An object associated with a Job object that holds its result:
it's available during the whole life the Job and after, even when
the Job didn't process yet. It's possible to use this object to
wait for the result/exception of the job to be available.

The result objects returns by the Pool::*_async() methods are of
this typeNc                    RV n         \        P                  ! 4       V n        RV n        RV n        W n        Ve   VP                  V 4       Wn        R# R# )a  
:param collector when not None, the notify_ready() method of
the collector will be called when the result from the Job is
ready
:param callback when not None, function to call when the
result becomes available (this is the parameter passed to the
Pool::*_async() methods.
FN)_success	threadingEvent_event_data
_collector	_callbackregister_result)r   r1   r:   s   &&&r   r   ApplyResult.__init__>  sJ     oo'
! %%d+'O !r   c                $   V P                  V4      '       g   \        RV,          4      hV P                  '       d   V P                  # V P                  ^ ,          ! V P                  ^,          4      P	                  V P                  ^,          4      h)z
Returns the result when it arrives. If timeout is not None and
the result does not arrive within timeout seconds then
TimeoutError is raised. If the remote call raised an exception
then that exception will be reraised by get().
zResult not available within %fs)rT   r   r   r   with_tracebackr   timeouts   &&r   r   ApplyResult.getQ  se     yy!!@7JKK===::jjmDJJqM*99$**Q-HHr   c                l    V P                   P                  V4       V P                   P                  4       # )zBWaits until the result is available or until timeout
seconds pass.)r   rT   isSetr   s   &&r   rT   ApplyResult.wait^  s)     	!{{  ""r   c                6    V P                   P                  4       # )z'Returns whether the call has completed.)r   r   rL   s   &r   readyApplyResult.readyd  s    {{  ""r   c                J    V P                  4       '       g   Q hV P                  # )zvReturns whether the call completed without raising an
exception. Will raise AssertionError if the result is not
ready.)r   r   rL   s   &r   
successfulApplyResult.successfulh  s     zz|||}}r   c                T   V P                  4       '       d   Q hWn        RV n        V P                  P	                  4        V P
                  e   V P
                  P                  V 4       V P                  e    V P                  V4       R# R#    \        P                  ! 4         R# ; i)zCalled by a Job object to tell the result is ready, and
provides the value of this result. The object will become
ready and successful. The collector's notify_ready() method
will be called, and the callback method tooTN)
r   r   r   r   setr   notify_readyr   r_   	print_exc)r   values   &&r   rB   ApplyResult._set_valueo  s~    
 ::<<
??&OO((.>>%&u% &&##%s   8B B'c                   V P                  4       '       d   Q h\        P                  ! 4       V n        RV n        V P
                  P                  4        V P                  e   V P                  P                  V 4       R# R# )zCalled by a Job object to tell that an exception occurred
during the processing of the function. The object will become
ready but not successful. The collector's notify_ready()
method will be called, but NOT the callback methodFN)	r   sysexc_infor   r   r   r   r   r   rL   s   &r   r   ApplyResult._set_exception  sX     ::<<\\^
??&OO((. 'r   )r   r   r   r   r   rt   rX   )r   r	   r
   r   r   r   r   rT   r   r   rB   r   r   rv   rw   s   @r   r;   r;   5  s3     (&I##&"/ /r   r;   c                   F   a  ] tR tRt o RtR tR tR tR
R ltR t	R	t
V tR# )AbstractResultCollectori  a  ABC to define the interface of a ResultCollector object. It is
basically an object which knows whuich results it's waiting for,
and which is able to get notify when they get available. It is
also able to provide an iterator over the results when they are
availablec                    Wn         R# zu
:param to_notify ApplyResult object to notify when all the
results we're waiting for become available. Can be None.
N
_to_notifyr   	to_notifys   &&r   r    AbstractResultCollector.__init__  s	    
 $r   c                    \        R4      h)Used to identify which results we're waiting for. Will
always be called BEFORE the Jobs get submitted to the work
queue, and BEFORE the __iter__ and _get_result() methods can
be called
:param apply_result ApplyResult object to add in our collection
"Children classes must implement itNotImplementedErrorr   r>   s   &&r   r   'AbstractResultCollector.register_result       ""FGGr   c                    \        R4      h)Called by the ApplyResult object (already registered via
register_result()) that it is now ready (ie. the Job's result
is available or an exception has been raised).
:param apply_result ApplyResult object telling us that the job
has been processed
r   r   r   s   &&r   r   $AbstractResultCollector.notify_ready  r   r   Nc                    \        R4      h)B  Called by the CollectorIterator object to retrieve the
result's values one after another (order defined by the
implementation)
:param idx The index of the result we want, wrt collector's order
:param timeout integer telling how long to wait (in seconds)
for the result at index idx to be available, or None (wait
forever)
r   r   r   idxr   s   &&&r   _get_result#AbstractResultCollector._get_result  s     ""FGGr   c                    \        V 4      # )z8Return a new CollectorIterator object for this collector)CollectorIteratorrL   s   &r   __iter__ AbstractResultCollector.__iter__  s     &&r   r   rX   )r   r	   r
   r   r   r   r   r   r   r   r   rv   rw   s   @r   r   r     s+     $HH	H' 'r   r   c                   @   a  ] tR tRt o RtR tR tR	R ltR tRt	V t
R# )
r   i  zAn iterator that allows to iterate over the result values
available in the given collector object. Equipped with an extended
next() method accepting a timeout argument. Created by the
AbstractResultCollector::__iter__() methodc                     Wn         ^ V n        R# )z':param AbstractResultCollector instanceNr   _idx)r   r1   s   &&r   r   CollectorIterator.__init__  s    #	r   c                    V # rX   r   rL   s   &r   r   CollectorIterator.__iter__  r[   r   Nc                    V P                   P                  V P                  V4      pT ;P                  ^,          un        TP                  4       '       g   Q hTP                  ^ 4      #   \         d    ^ T n        \        h ^ T n        h ; i)zwReturn the next result value in the sequence. Raise
StopIteration at the end. Can raise the exception raised by
the Job)r   r   r   
IndexErrorrh   r   r   )r   r   r>   s   && r   rg   CollectorIterator.next  s~    	??66tyy'JL 			Q	!!####""  	 DI	DIs   &A* *!Bc                "    V P                  4       # rX   )rg   rL   s   &r   __next__CollectorIterator.__next__  s    yy{r   r   rX   )r   r	   r
   r   r   r   r   rg   r   r   rv   rw   s   @r   r   r     s#     2

#" r   r   c                   H   a  ] tR tRt o RtR	R ltR tR	R ltR	R ltRt	V t
R# )
r5   i  zAn AbstractResultCollector implementation that collects the
values of the ApplyResult objects in the order they become ready. The
CollectorIterator object returned by __iter__() will iterate over
them in the order they become readyNc                    \         P                  W4       \        P                  ! 4       V n        . V n        ^ V n        R# r   )r   r   r   	Condition_cond_collection	_expectedr   s   &&r   r   !UnorderedResultCollector.__init__  s1    
 	 ((9((*
r   c                8    V ;P                   ^,          un         R# r   N)r   r   s   &&r   r   (UnorderedResultCollector.register_result  s     	!r   c                @   V P                   P                  4         WP                  8  d   \        hV\	        V P
                  4      8  d.   V P
                  V,          V P                   P                  4        # V\	        V P
                  4      8w  d   \        4       hV P                   P                  VR7        V P
                  V,          V P                   P                  4        #   \         d    \        R4      hi ; i  T P                   P                  4        i ; i)aM  Called by the CollectorIterator object to retrieve the
result's values one after another, in the order the results have
become available.
:param idx The index of the result we want, wrt collector's order
:param timeout integer telling how long to wait (in seconds)
for the result at index idx to be available, or None (wait
forever)
)r   z!Timeout while waiting for results)	r   acquirer   r   lenr   releaserT   r   r   s   &&&r   r   $UnorderedResultCollector._get_result  s     	

	!nn$  s4++,,'', JJ  D,,-- l"

0L++C0
 JJ 	 " L&'JKKL JJ s%   AD 9A D :C' 'C>>D Dc                   RpV P                   P                  4         V P                  P                  V4       \	        V P                  4      ^8H  pV P                   P                  4        V P                   P                  4        V'       d7   V P                  e'   V P                  P                  \        V 4      4       R# R# R#   T P                   P                  4        i ; ir   FN)
r   r   r   ri   r   	notifyAllr   r   rB   r/   )r   r>   
first_items   && r   r   %UnorderedResultCollector.notify_ready  s     


	!##L1d../14JJJ  "JJ $//5OO&&tDz2 6: JJ s   AC C!)r   r   r   rX   r   r	   r
   r   r   r   r   r   r   r   rv   rw   s   @r   r5   r5     s#     +
!83 3r   r5   c                   D   a  ] tR tRt o RtR	R ltR tR
R ltR tRt	V t
R# )r-   i+  zAn AbstractResultCollector implementation that collects the
values of the ApplyResult objects in the order they have been
submitted. The CollectorIterator object returned by __iter__()
will iterate over them in the order they have been submittedNc                    \         P                  W4       . V n        \        P                  ! 4       V n        ^ V n        W n        R# )a9  
:param to_notify ApplyResult object to notify when all the
results we're waiting for become available. Can be None.
:param as_iterator boolean telling whether the result value
set on to_notify should be an iterator (available as soon as 1
result arrived) or a list (available only after the last
result arrived)
N)r   r   _resultsr   Lock_lock
_remaining_as_iterator)r   r   r,   s   &&&r   r   OrderedResultCollector.__init__1  s4     	 ((9^^%
'r   c                n    V P                   P                  V4       V ;P                  ^,          un        R# r   )r   ri   r   r   s   &&r   r   &OrderedResultCollector.register_result@  s$     	\*1r   c                N    V P                   V,          pVP                  V4       V# )r   )r   rT   )r   r   r   ress   &&& r   r   "OrderedResultCollector._get_resultJ  s#     mmC 
r   c                $   RpRpV P                   P                  4         V P                  ^ 8  g   Q h\        V P                  4      V P                  8H  pV ;P                  ^,          un        V P                  ^ 8H  pV P                   P                  4        V P                  e   V P                  '       d/   V'       d'   V P                  P                  \        V 4      4       R# V P                  '       gR   V'       dH    V P                   Uu. uF  qDP                  ^ 4      NK  	  ppV P                  P                  V4       R# R# R# R#   T P                   P                  4        i ; iu upi    T P                  P                  4         R# ; ir   )r   r   r   r   r   r   r   r   rB   r/   r   r   )r   r>   	got_firstgot_lastrlsts   &&    r   r   #OrderedResultCollector.notify_readyW  s'    	

	!??Q&&&T]]+t>IOOq O1,HJJ ??&   Y**4:6&&&84-1]];]558]C; OO..s3 ,4& ' JJ  <5OO224s*   AE  E0 E+'E0 E(+E0 0F)r   r   r   r   )NTrX   r   rw   s   @r   r-   r-   +  s$     D
(4 4r   r-   )r   r   r_   api__all__r   	Exceptionr   objectr   r<   rj   r;   r   r   r5   r-   r   r   r   <module>r     s   F    >
"	9 	
s6 sl, ,8 V/& V/r-'f -'`   FG36 G3TG44 G4r   