python (3.12.0)

(root)/
lib/
python3.12/
multiprocessing/
__pycache__/
pool.cpython-312.opt-1.pyc

̑eddgZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZm
Z
ddlmZdZd	Zd
ZdZej(ZdZd
ZGddeZGddZdZGddeZ		d#dZdZGddeZ Gdde!Z"Gdde!Z#e#Z$Gdde#Z%Gdde!Z&Gd d!e&Z'Gd"de"Z(y)$Pool
ThreadPoolN)util)get_contextTimeoutError)waitINITRUNCLOSE	TERMINATEc$tt|SN)listmapargss H/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/multiprocessing/pool.pymapstarr/sT
cLttj|d|dS)Nrr)r	itertoolsstarmaprs rstarmapstarr2s"	!!$q'47344rceZdZdZdZy)RemoteTracebackc||_yrtb)selfrs  r__init__zRemoteTraceback.__init__:s	rc|jSrrr s r__str__zRemoteTraceback.__str__<swwrN)__name__
__module____qualname__r!r$rrrr9srrceZdZdZdZy)ExceptionWithTracebackctjt|||}dj|}||_d|z|_y)Nz

"""
%s""")	tracebackformat_exceptiontypejoinexcr)r r1rs   rr!zExceptionWithTraceback.__init__@s:

'
'S	3
;
WWR[ 2%rc>t|j|jffSr)rebuild_excr1rr#s r
__reduce__z!ExceptionWithTraceback.__reduce__EsTXXtww///rN)r%r&r'r!r4r(rrr*r*?s&
0rr*c&t||_|Sr)r	__cause__)r1rs  rr3r3Hs#B'CMJrc.eZdZdZfdZdZdZxZS)MaybeEncodingErrorzVWraps possible unpickleable errors, so they can be
    safely sent through the socket.ct||_t||_tt||j|jyr)reprr1valuesuperr8r!)r r1r;	__class__s   rr!zMaybeEncodingError.__init__Ts39%[

 $04::Frc<d|jd|jdS)NzError sending result: 'z'. Reason: '')r;r1r#s rr$zMaybeEncodingError.__str__Ys=AZZ=AXXG	Grc<d|jjd|dS)N<z: >)r=r%r#s r__repr__zMaybeEncodingError.__repr__]s!^^44d;;r)r%r&r'__doc__r!r$rC
__classcell__r=s@rr8r8Ps'G
G<rr8c||/t|tr|dk\stdj||j}|j
}t
|dr4|jj|jj|||d}||r`||kr[	|}	|	tjdn;|	\}
}}}
}	d||
i|f}	||
||fdx}	x}
x}x}x}
}|dz
}|S|r||kr[tjd
|zy#ttf$rtjdY?wxYw#t$r.}|r|turt!||j"}d|f}Yd}~d}~wwxYw#t$r>}t%||d}tjd	|z||
|d|ffYd}~d}~wwxYw)NrzMaxtasks {!r} is not valid_writerrz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFz0Possible encoding error while sending result: %szworker exiting after %d tasks)
isinstanceintAssertionErrorformatputgethasattrrHclose_readerEOFErrorOSErrorrdebug	Exception_helper_reraises_exceptionr*
__traceback__r8)inqueueoutqueueinitializerinitargsmaxtaskswrap_exceptionrMrN	completedtaskjobifuncrkwdsresultewrappeds                  rworkerrgasz(C'@+3q=9@@JKK
,,C
++Cw	" XI

xI,@	5D
<JJ78#' QdD	 D$/$/0F
	,a !4877s7V7d7TDQ	7
xI,@8	JJ.:;3'"	JJBC		 $.H"H*1aoo>QZF	 	,(F1I6GJJI
a%)*++		,sBD
D:E4$D76D7:	E1$E,,E14	F;=4F66F;c|)z@Pickle-able helper function for use by _guarded_task_generation.r()exs rrVrVs
Hrc2eZdZdZddfd
ZfdZxZS)
_PoolCachez
    Class that implements a cache for the Pool class that will notify
    the pool management threads every time the cache is emptied. The
    notification is done by the use of a queue that is provided when
    instantiating the cache.
    Nnotifierc2||_t||i|yr)rmr<r!)r rmrrcr=s    rr!z_PoolCache.__init__s 

$'$'rc`t|||s|jjdyyr)r<__delitem__rmrM)r itemr=s  rrpz_PoolCache.__delitem__s,
D!MMd#r)r%r&r'rDr!rprErFs@rrkrks+/(
$
$rrkceZdZdZdZedZ		d(dZeje
fdZdZd	Z
ed
ZedZdZed
ZedZdZdZdifdZd)dZd)dZ		d*dZdZd+dZd+dZdiddfdZ		d*dZ		d*dZed)dZe dZ!edZ"edZ#edZ$d Z%d!Z&d"Z'd#Z(ed$Z)e d%Z*d&Z+d'Z,y),rzS
    Class which supports an async version of applying functions to arguments.
    Tc&|j|i|SrProcess)ctxrrcs   rruzPool.Processss{{D)D))rNr(cg|_t|_|xs
t|_|jt
j|_|jj|_	t|j|_||_||_
||_|tj xsd}|dkrt#d| t%|t&r|dkrt#d|t)|st+d||_	|j/|j9}t;j<t>j@|j|j|j|jB|j,|j|jD|jF|j|j|j|jH||jf|_%d|jJ_&tN|jJ_|jJjQt;j<t>jR|j|jT|jF|j|jf|_+d|jV_&tN|jV_|jVjQt;j<t>jX|jF|jZ|jf|_.d|j\_&tN|j\_|j\jQt_j`||jb|j|jD|jF|j|j|jJ|jV|j\|jf	d	
|_2tN|_y#t0$rQ|jD]}|j2|j5!|jD]}|j7wxYw)Nrlrz&Number of processes must be at least 1rz/maxtasksperchild must be a positive int or Nonezinitializer must be a callabletargetrT)rexitpriority)3_poolr
_stater_ctx
_setup_queuesqueueSimpleQueue
_taskqueue_change_notifierrk_cache_maxtasksperchild_initializer	_initargsos	cpu_count
ValueErrorrIrJcallable	TypeError
_processes_repopulate_poolrUexitcode	terminater0_get_sentinels	threadingThreadr_handle_workersru_inqueue	_outqueue_wrap_exception_worker_handlerdaemonrstart
_handle_tasks
_quick_put
_task_handler_handle_results
_quick_get_result_handlerrFinalize_terminate_pool
_terminate)r 	processesrZr[maxtasksperchildcontextp	sentinelss        rr!z
Pool.__init__sV
,{}	++-!%		 5 5 7 $*?*?@!1'!+!Iq=EFF'.48HA8M !RSS"8K+@<==#	!!#'')	(//''++t		4<<//4::t}}dnn##T^^T5K5K&&	43H3HJ '+#&)#""$'--%%//4??DNN**dkk+
%)!$'!  "(//''..$//4;;? '+#&)#""$--$&&//4==$..$**'')=)=t?Q?Q&&5]	ZZ
"::%KKM
"ZZ


	s
O''$Q5Qc|j|k(r<|d|t|t|dd|jj	dyyy)Nz&unclosed running multiprocessing pool )sourcer)r}ResourceWarninggetattrrrM)r _warnrs   r__del__zPool.__del__
sT;;#:4(C!$
0t/6B%%))$/Crc
|j}d|jd|jd|jdt	|j
d	S)NrA.z state=z pool_size=rB)r=r&r'r}lenr|)r clss  rrCz
Pool.__repr__sQnnCNN#1S%5%5$67
& _-Q0	1rcj|jjg}|jjg}g||Sr)rrQr)r task_queue_sentinelsself_notifier_sentinelss   rrzPool._get_sentinelss< $ 6 67#'#8#8#@#@"A@%@(?@@rcX|Dcgc]}t|dr|jc}Scc}w)Nsentinel)rOr)workersrgs  r_get_worker_sentinelszPool._get_worker_sentinelss18F"6:68	88s'cd}ttt|D]A}||}|jt	j
d|z|j
d}||=C|S)zCleanup after any worker processes which have exited due to reaching
        their specified lifetime.  Returns True if any workers were cleaned up.
        Fcleaning up worker %dT)reversedrangerrrrTr0)poolcleanedrargs    r_join_exited_workerszPool._join_exited_workers!sg
%D	*+	A!WF*

2Q67
G	rc|j|j|j|j|j|j
|j|j|j|j|j
Sr)_repopulate_pool_staticr~rurr|rrrrrrr#s rrzPool._repopulate_pool1s_++DIIt||,0OO,0JJ

,0NND<M<M,0NN,0,B,B,0,@,@
B	Brc
"t|t|z
D]u}
||t||||||	f}|jj	dd|_d|_|j
|j|tjdwy)zBring the number of pool processes up to the specified number,
        for use after reaping workers which have exited.
        rxru
PoolWorkerTzadded workerN)
rrrgnamereplacerrappendrrT)rvrurrrXrYrZr[rr]raws            rrzPool._repopulate_pool_static:sy3t9,-
	'AF%x)&(8,./A
VV^^I|<AFAH
GGIKKNJJ~&
	'rc
ltj|rtj||||||||||	
yy)zEClean up any exited workers and start replacements for them.
        N)rrr)
rvrurrrXrYrZr[rr]s
          r_maintain_poolzPool._maintain_poolMs=$$T*((gy$)0(K)13C)7
9+rc|jj|_|jj|_|jjj
|_|jjj|_	yr)
r~rrrrHsendrrQrecvrr#s rrzPool._setup_queuesYsX		--/
..0--//44..0055rc@|jtk7rtdy)NzPool not running)r}rrr#s r_check_runningzPool._check_running_s;;#/00rcD|j|||jS)zT
        Equivalent of `func(*args, **kwds)`.
        Pool must be running.
        )apply_asyncrN)r rbrrcs    rapplyz
Pool.applycs"
dD15577rcN|j||t|jS)zx
        Apply `func` to each element in `iterable`, collecting the results
        in a list that is returned.
        )
_map_asyncrrNr rbiterable	chunksizes    rrzPool.mapjs"
tXw	BFFHHrcN|j||t|jS)z
        Like `map()` method but the elements of the `iterable` are expected to
        be iterables as well and will be unpacked as arguments. Hence
        `func` and (a, b) becomes func(a, b).
        )rrrNrs    rrzPool.starmapqs"tX{IFJJLLrc6|j||t|||S)z=
        Asynchronous version of `starmap()` method.
        )rrr rbrrcallbackerror_callbacks      r
starmap_asynczPool.starmap_asyncys"
tX{I'9	9rc#K	d}t|D]\}}||||fify#t$r}|dzt|fifYd}~yd}~wwxYww)zProvides a generator of tasks for imap and imap_unordered with
        appropriate handling for iterables which throw exceptions during
        iteration.rN)	enumeraterUrV)r 
result_jobrbrraxres       r_guarded_task_generationzPool._guarded_task_generationse	JA!(+
61!1dQD"55
6	Jqs$>bII	Js)A$A	AAAAAc|j|dk(rOt|}|jj|j	|j
|||jf|S|dkrtdj|tj|||}t|}|jj|j	|j
t||jfd|DS)zP
        Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
        rzChunksize must be 1+, not {0:n}c3.K|]
}|D]}|ywrr(.0chunkrqs   r	<genexpr>zPool.imap.<locals>.<genexpr>?U?D?D?)rIMapIteratorrrMr_job_set_lengthrrLr
_get_tasksrr rbrrrdtask_batchess      rimapz	Pool.imaps	
>!$'FOO11&++tXN&&

M1} 5<<!#$$ ??49EL!$'FOO11&++292>@&&	
@f??rc|j|dk(rOt|}|jj|j	|j
|||jf|S|dkrtdj|tj|||}t|}|jj|j	|j
t||jfd|DS)zL
        Like `imap()` method but ordering of results is arbitrary.
        rzChunksize must be 1+, not {0!r}c3.K|]
}|D]}|ywrr(rs   rrz&Pool.imap_unordered.<locals>.<genexpr>rr)rIMapUnorderedIteratorrrMrrrrrLrrrrs      rimap_unorderedzPool.imap_unordereds	
>*40FOO11&++tXN&&

M1} 5<<YGII??49EL*40FOO11&++292>@&&	
@f??rc|jt|||}|jj|jd|||fgdf|S)z;
        Asynchronous version of `apply()` method.
        rN)rApplyResultrrMr)r rbrrcrrrds       rrzPool.apply_asyncsL
	
T8^<v{{AtT4@A4HI
rc6|j||t|||S)z9
        Asynchronous version of `map()` method.
        )rrrs      r	map_asynczPool.map_asyncs"
tXw	8	rc|jt|dst|}|5tt	|t	|j
dz\}}|r|dz
}t	|dk(rd}tj|||}t||t	|||}	|jj|j|	j||df|	S)zY
        Helper function to implement map, starmap and their async counterparts.
        __len__Nrrr)
rrOrdivmodrr|rr	MapResultrrMrr)
r rbrmapperrrrextrarrds
          rrzPool._map_asyncs
	
x+H~H%c(mS_q5HIIuQ	x=AItXyA4CM8*8:--fkk.4.:<	
	

rct|||js"|j|js!yy)N)timeout)r	emptyrN)rchange_notifierrs   r_wait_for_updateszPool._wait_for_updatess2Y(!'')!"'')rctj}|jtk(s|r~|jtk7rk|j|||||||	|
||
g|j
||
}|j|||jtk(rU|r|jtk7rk|jdtjdy)Nzworker handler exiting)rcurrent_threadr}rr
rrrrMrrT)rcache	taskqueuervrurrrXrYrZr[rr]rrthreadcurrent_sentinelss                 rrzPool._handle_workerss
))+mms"u)1KsGYg'h/
A!O#";";D"A NI N!!"3_Emms"u)1K	

d

+,rc0tj}t|jdD]}\}}d}	|D]5}|jt
k7rt
jdn>	||7|r)t
jd|r|dnd}||dz	dx}x}}
v	dx}x}}
nt
jd	t
jd|jdt
jd	|D]
}|d	t
jdy#t$r;}	|dd\}
}	||
j|d|	fn#t$rYnwxYwYd}	~	+d}	~	wwxYw#dx}x}}
wxYw#t$rt
jd
YwxYw)Nz'task handler found thread._state != RUNFzdoing set_length()rrztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exiting)
rr	iterrNr}rrrTrU_setKeyErrorrMrS)
rrMrYrr
rtaskseq
set_lengthr_rer`idxrs
             rrzPool._handle_taskss))+#'	

t#<	4GZD
,#D}}+

#LM!D	"

#78)-d1g2"37+(,++w'+++w1	44
JJ23
	JJJHILL
JJAB
D	

	

)*=%!#'8S!!#JOOC%<'! !	!(,++w	JJJHI	Jsl/E)$D",-E)A
E4"	E&+E!4EE!	E	E!E	E!E)!E&&E))E14FFctj}		|}|jtk7rt	j
dn;|t	j
dn#|\}}}	||j||dx}x}}l|rk|jtk7rX	|}|t	j
d5|\}}}	||j||dx}x}}|r|jtk7rXt|drIt	j
d	tdD]%}|jjsn	|'t	j
dt||jy#ttf$rt	j
dYywxYw#t$rY*wxYw#ttf$rt	j
dYywxYw#t$rYwxYw#ttf$rYwxYw)	Nz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelrQz"ensuring that outqueue is not full
z7result handler exiting: len(cache)=%s, thread._state=%s)rr	rSrRrrTr}rrrr
rOrrQpollr)rYrNr
rr_r`raobjs        rrzPool._handle_results=s))+
u
}}#

IJ|

89KCC
c
3' $#D#3+.

2
u
|

CDKCC
c
3' $#D#3

2"8Y'JJ;<
rA#++002E	

L%j&--	)eX&


KL
 

X&


KL


X&

sYE/&FF)>G3G#/$FF	F&%F&)$GG	G G #G54G5c#tKt|}	ttj||}|sy||f)wr)rtuplerislice)rbitsizers    rrzPool._get_tasksys=
"Xi&&r401A)O	s68ctd)Nz:pool objects cannot be passed between processes or pickled)NotImplementedErrorr#s rr4zPool.__reduce__s!J	rctjd|jtk(r<t|_t|j
_|jjdyy)Nzclosing pool)rrTr}rrrrrMr#s rrPz
Pool.closesH

>";;#DK*/D  '!!%%d+rcdtjdt|_|j	y)Nzterminating pool)rrTr
r}rr#s rrzPool.terminates 

%&rctjd|jtk(rt	d|jt
tfvrt	d|jj|jj|jj|jD]}|jy)Nzjoining poolzPool is still runningzIn unknown state)rrTr}rrrr
rr0rrr|)r rs  rr0z	Pool.joins

>";;#455
[[	 2
2/00!!#!!!#	A
FFH	rcptjd|jj|j	rw|j
j
r\|j
jtjd|j	r|j
j
rZyyyy)Nz7removing tasks from inqueue until task handler finishedr)
rrT_rlockacquireis_aliverQrrtimesleep)rXtask_handlerrs   r_help_stuff_finishzPool._help_stuff_finishs}	

LM ##%'//*>*>*@OO  "JJqM##%'//*>*>*@%*@%rc
dtjdt|_|j	dt|_tjd|j||t
||jst
|	dk7rtdt|_|j	d|j	dtjdtj|ur|j|rHt|ddr9tjd|D]}
|
j|
j!tjdtj|ur|jtjd	tj|ur|j|rpt|ddr`tjd
|D]E}
|
jstjd|
jz|
jGyyy)Nzfinalizing poolz&helping task handler/workers to finishrz/Cannot have cache with result_handler not alivezjoining worker handlerrzterminating workerszjoining task handlerzjoining result handlerzjoining pool workersr)rrTr
r}rMr+rr'rKrr	r0rOrrpid)rrrXrYrrworker_handlerr*result_handlerr
rs           rrzPool._terminate_pools	

$%
!*D!'

;<wc$i@'')E
a AC
C!*D!T	

+,##%^;!GDG[1JJ,-
"::%KKM
"	

)*##%\9

+,##%^;!GDG[1JJ-.
::<JJ6>?FFH	
24rc&|j|Sr)rr#s r	__enter__zPool.__enter__src$|jyr)r)r exc_typeexc_valexc_tbs    r__exit__z
Pool.__exit__sr)NNr(NNr)NNN)r)-r%r&r'rDrstaticmethodrur!warningswarnrrrCrrrrrrrrrrrrrrrrrrrclassmethodrrrrr4rPrr0r+rr1r6r(rrrrsO**CE04Of%MMs01A
88

B''$	9	961 "8IMFJ9	J@:@8&(b4BFKO:""
--(++++Z9)9)v
,

33jrcXeZdZdZdZdZddZddZdZe	e
jZy)	rc||_tj|_t	t
|_|j|_||_||_	||j|j<yr)
r|rEvent_eventnextjob_counterrr	_callback_error_callback)r rrrs    rr!zApplyResult.__init__sO
oo'%	kk!-!%DIIrc6|jjSr)r>is_setr#s rreadyzApplyResult.readys{{!!##rcn|jstdj||jS)Nz{0!r} not ready)rErrL_successr#s r
successfulzApplyResult.successfuls,zz|.55d;<<}}rNc:|jj|yr)r>r	r rs  rr	zApplyResult.waits!rc|j||jst|jr|jS|jr)r	rErrG_valuerJs  rrNzApplyResult.gets8		'zz|==;;++rc^|\|_|_|jr'|jr|j|j|jr'|js|j|j|jj|j|j=d|_yr)	rGrLrArBr>setrrr|r rars   rrzApplyResult._setss%("
t{>>dmmNN4;;'

  -KK		"
rr)
r%r&r'r!rErHr	rNrr:typesGenericAlias__class_getitem__r(rrrrs3&$
"$E$6$67rrceZdZdZdZy)rctj||||d|_dg|z|_||_|dkr9d|_|jj|j|j=y||zt||zz|_y)NrTr)rr!rGrL
_chunksize_number_leftr>rNrrbool)r rrlengthrrs      rr!zMapResult.__init__sT4,:		<
fvo#> !DKKOODII& &	 1D)9K4L LDrc|xjdzc_|\}}|r|jr||j||jz|dz|jz|jdk(r`|jr|j	|j|j
|j=|jjd|_	yy|s|jrd|_||_|jdk(r`|jr|j|j|j
|j=|jjd|_	yy)NrrF)rVrGrLrUrArrr>rNr|rB)r rasuccess_resultsuccessrds     rrzMapResult._set)sQ(t}}CIDKK$//)1Q3*?@  A%>>NN4;;/KK		*!!
&t}} %
$  A%''((5KK		*!!

&rN)r%r&r'r!rr(rrrrs
M"rrc0eZdZdZdZddZeZdZdZy)rcB||_tjtj|_tt|_|j|_tj|_d|_d|_
i|_||j|j<y)Nr)r|r	ConditionLock_condr?r@rrcollectionsdeque_items_index_length	_unsorted)r rs  rr!zIMapIterator.__init__Gsp
(()9:
%	kk!'')!%DIIrc|Srr(r#s r__iter__zIMapIterator.__iter__RsrNc|j5	|jj}ddd\}}|r|S|#t$r|j|j
k(rd|_td|jj|	|jj}n;#t$r/|j|j
k(rd|_tdtdwxYwYwxYw#1swYxYwr)
r`rcpopleft
IndexErrorrdrer|
StopIterationr	r)r rrqr[r;s     rr?zIMapIterator.nextUs
ZZ	1

1{{**,	1 L!
1;;$,,.!%DJ'T1

(1;;..0D!1{{dll2%)
+5&D0	1

1	1	1s?C$<AC!B#"C!#8CC!C$ C!!C$$C-c|j5|j|k(r|jj||xjdz
c_|j|jvrn|jj|j}|jj||xjdz
c_|j|jvrn|jj
n||j|<|j|jk(r|j|j=d|_
dddy#1swYyxYwNr)r`rdrcrrfpopnotifyrerrr|rOs   rrzIMapIterator._setms
ZZ	"{{a""3'q kkT^^3..,,T[[9CKK&&s+KK1$KkkT^^3

!!#$'q!{{dll*KK		*!
	"	"	"sCD=A!D==Ec|j5||_|j|jk(r8|jj|j|j
=d|_dddy#1swYyxYwr)r`rerdrprrr|)r rXs  rrzIMapIterator._set_length~s\
ZZ	"!DL{{dll*

!!#KK		*!
	"	"	"sAA//A8r)	r%r&r'r!rhr?__next__rrr(rrrrEs"	&,H"""rrceZdZdZy)rcH|j5|jj||xjdz
c_|jj	|j|j
k(r|j|j=d|_dddy#1swYyxYwrn)	r`rcrrdrprerrr|rOs   rrzIMapUnorderedIterator._setsu
ZZ	"KKs#KK1KJJ{{dll*KK		*!

	"	"	"sBBB!N)r%r&r'rr(rrrrs"rrcZeZdZdZedZd
dZdZdZedZ	edZ
d	Zy)rFcddlm}||i|S)Nrrt)dummyru)rvrrcrus    rruzThreadPool.Processs"%%%rNc4tj||||yr)rr!)r rrZr[s    rr!zThreadPool.__init__s

dI{H=rctj|_tj|_|jj|_|jj|_yr)rrrrrMrrNrr#s rrzThreadPool._setup_queuessD))+
**,--++..,,rc0|jjgSr)rrQr#s rrzThreadPool._get_sentinelss%%--..rcgSrr()rs rrz ThreadPool._get_worker_sentinelss	rc		|jd#tj$rYnwxYwt|D]}|j	dy)NF)block)rNrEmptyrrM)rXr*rras    rr+zThreadPool._help_stuff_finishsR	%({{		t	AKK	s,,c.tj|yr)r(r))r rrrs    rrzThreadPool._wait_for_updatess

7r)NNr()r%r&r'rr7rur!rrrr+rr(rrrrsUO&&>-/r)Nr(NF))__all__rarrrrr(r-rPr8r,rrr
connectionr	r
rrr
countr@rrrUrr*r3r8rgrVdictrkobjectrrAsyncResultrrrrr(rr<module>rs<
 	'	ioo5i00<<"GK+<Z
$$.v6vx)8&)8V%"%"V?"6?"J	"L	"$$r