python (3.12.0)

(root)/
lib/
python3.12/
concurrent/
futures/
__pycache__/
process.cpython-312.opt-1.pyc

ˑeG"dZdZddlZddlmZddlZddlZddlZddl	m
Z
ddlZddlZddl
mZddlZddlZddlmZej&ZdaGd	d
ZdZej0edZd
ZGddeZGddZdZGddeZ GddeZ!GddeZ"Gdde
Z#dZ$dZ%		d'dZ&d(dZ'Gdd ejPZ)da*da+d!Z,d"Z-Gd#d$ej\Z/Gd%d&ej`Z1y))a-	Implements ProcessPoolExecutor.

The following diagram and text describe the data-flow through the system:

|======================= In-process =====================|== Out-of-process ==|

+----------+     +----------+       +--------+     +-----------+    +---------+
|          |  => | Work Ids |       |        |     | Call Q    |    | Process |
|          |     +----------+       |        |     +-----------+    |  Pool   |
|          |     | ...      |       |        |     | ...       |    +---------+
|          |     | 6        |    => |        |  => | 5, call() | => |         |
|          |     | 7        |       |        |     | ...       |    |         |
| Process  |     | ...      |       | Local  |     +-----------+    | Process |
|  Pool    |     +----------+       | Worker |                      |  #1..n  |
| Executor |                        | Thread |                      |         |
|          |     +----------- +     |        |     +-----------+    |         |
|          | <=> | Work Items | <=> |        | <=  | Result Q  | <= |         |
|          |     +------------+     |        |     +-----------+    |         |
|          |     | 6: call()  |     |        |     | ...       |    |         |
|          |     |    future  |     |        |     | 4, result |    |         |
|          |     | ...        |     |        |     | 3, except |    |         |
+----------+     +------------+     +--------+     +-----------+    +---------+

Executor.submit() called:
- creates a uniquely numbered _WorkItem and adds it to the "Work Items" dict
- adds the id of the _WorkItem to the "Work Ids" queue

Local worker thread:
- reads work ids from the "Work Ids" queue and looks up the corresponding
  WorkItem from the "Work Items" dict: if the work item has been cancelled then
  it is simply removed from the dict, otherwise it is repackaged as a
  _CallItem and put in the "Call Q". New _CallItems are put in the "Call Q"
  until "Call Q" is full. NOTE: the size of the "Call Q" is kept small because
  calls placed in the "Call Q" can no longer be cancelled with Future.cancel().
- reads _ResultItems from "Result Q", updates the future stored in the
  "Work Items" dict and deletes the dict entry

Process #1..n:
- reads _CallItems from "Call Q", executes the calls, and puts the resulting
  _ResultItems in "Result Q"
z"Brian Quinlan (brian@sweetapp.com)N)_base)Queue)partial)format_exceptionFc$eZdZdZdZdZdZy)
_ThreadWakeupcXd|_tjd\|_|_y)NF)duplex)_closedmpPipe_reader_writerselfs N/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/concurrent/futures/process.py__init__z_ThreadWakeup.__init__Es %'WWE%:"dlc|js<d|_|jj|jjyyNT)rrcloserrs rrz_ThreadWakeup.closeIs5||DLLL LL rcT|js|jjdyy)Nr)rr
send_bytesrs rwakeupz_ThreadWakeup.wakeupOs ||LL##C(rc|jsQ|jjr6|jj|jjr5yyyN)rrpoll
recv_bytesrs rclearz_ThreadWakeup.clearSs@||,,##%''),,##%rN)__name__
__module____qualname__rrrrrrrrDs;!)*rrcdattj}|D]\}}|j	|D]\}}|jyr)_global_shutdownlist_threads_wakeupsitemsrjoin)r(_
thread_wakeupts    r_python_exitr-YsZ!'')*E!=1	r=ceZdZdZdZy)_RemoteTracebackc||_yrtb)rr4s  rrz_RemoteTraceback.__init__ys	rc|jSrr3rs r__str__z_RemoteTraceback.__str__{swwrN)r r!r"rr6r#rrr1r1xsrr1ceZdZdZdZy)_ExceptionWithTracebackcdjtt|||}||_d|j_d|z|_y)Nz

"""
%s""")r)rtypeexc
__traceback__r4)rr<r4s   rrz _ExceptionWithTraceback.__init__s?
WW%d3ib9
:"& 2%rc>t|j|jffSr)_rebuild_excr<r4rs r
__reduce__z"_ExceptionWithTraceback.__reduce__sdhh000rN)r r!r"rr@r#rrr8r8~s&1rr8c&t||_|Sr)r1	__cause__)r<r4s  rr?r?s$R(CMJrceZdZdZy)	_WorkItemc<||_||_||_||_yr)futurefnargskwargs)rrFrGrHrIs     rrz_WorkItem.__init__s	rNr r!r"rr#rrrDrDrrDceZdZddZy)_ResultItemNc<||_||_||_||_yr)work_id	exceptionresultexit_pid)rrOrPrQrRs     rrz_ResultItem.__init__s" 
rNNNrJr#rrrMrMs!rrMceZdZdZy)	_CallItemc<||_||_||_||_yr)rOrGrHrI)rrOrGrHrIs     rrz_CallItem.__init__s	rNrJr#rrrUrUrKrrUc.eZdZdZdfd	ZfdZxZS)
_SafeQueuez=Safe Queue set exception to the future object linked to a jobcR||_||_||_t|||y)N)ctx)pending_work_items
shutdown_lockr+superr)rmax_sizerZr[r\r+	__class__s      rrz_SafeQueue.__init__s-"4**
s+rct|trtt|||j}tdj
dj||_|jj|jd}|j5|jjddd||jj!|yyt"|I||y#1swY9xYw)Nz

"""
{}"""r:)
isinstancerUrr;r=r1formatr)rBr[poprOr\r+rrF
set_exceptionr]_on_queue_feeder_error)reobjr4	work_itemr_s     rrez!_SafeQueue._on_queue_feeder_errorsc9%!$q'1aoo>B*>+@+@+MNAK//33CKKFI##
,""))+
,
$  ..q1%
G*1c2
,
,sC%%C.)r)r r!r"__doc__rre
__classcell__r_s@rrXrXsG,
3
3rrXc'jKt|}	ttj||}|sy|'w)z, Iterates over zip()ed iterables in chunks. N)ziptuple	itertoolsislice)	chunksize	iterablesitchunks    r_get_chunksrus9	iB
i&&r956	s13c2|Dcgc]}||	c}Scc}w)z Processes a chunk of an iterable passed to map.

    Runs the function passed to map() on a chunk of the
    iterable passed to map.

    This function is run in a separate process.

    r#)rGrtrHs   r_process_chunkrws#(($BI(((sc	|jt||||y#t$r=}t||j}|jt|||Yd}~yd}~wwxYw)z.Safely send back the given result or exception)rQrPrRrPrRN)putrM
BaseExceptionr8r=)result_queuerOrQrPrRrfr<s       r_sendback_resultr}sh9WV/88M	N9%a9W.68	9	99s!	A'3A""A'cB|	||d}d}	|j	d}|$|jt
jy||dz
}||k\rt
j}	|j|ji|j}t||j||~~|y#t$r$tjjddYywxYw#t$r9}	t|	|	j}
t||j|
|	Yd}	~	rd}	~	wwxYw)
aEvaluates calls from call_queue and places the results in result_queue.

    This worker is run in a separate process.

    Args:
        call_queue: A ctx.Queue of _CallItems that will be read and
            evaluated by the worker.
        result_queue: A ctx.Queue of _ResultItems that will written
            to by the worker.
        initializer: A callable initializer, or None
        initargs: A tuple of args for the initializer
    NzException in initializer:T)exc_inforblockr.)rQrRry)r{rLOGGERcriticalgetrzosgetpidrGrHrIr}rOr8r=)
call_queuer|initializerinitargs	max_tasks	num_tasksrR	call_itemrrfr<s           r_process_workerrs3	"IH
NNN.	RYY[) NII%99;			innA	0@0@AA
\9+<+<Q&.
0
9	LL!!"=!M
		*	0)!Q__=C\9+<+<&.
0
0	0s)B,'&C,*CC	D%/DDc^eZdZdZfdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZxZS)
_ExecutorManagerThreadatManages the communication between this process and the worker processes.

    The manager is run in a local thread.

    Args:
        executor: A reference to the ProcessPoolExecutor that owns
            this thread. A weakref will be own by the manager as well as
            references to internal objects used to introspect the state of
            the executor.
    c|j|_|j|_|j|jfd}t	j
|||_|j|_|j|_
|j|_|j|_|j|_|j"|_t&|Qy)Nctjjd|5|jdddy#1swYyxYw)Nz?Executor collected: triggering callback for QueueManager wakeup)rutildebugr)r*r+r\s   r
weakref_cbz3_ExecutorManagerThread.__init__.<locals>.weakref_cb.s=
GGMM1
2
'$$&
'
'
's	<A)_executor_manager_thread_wakeupr+_shutdown_lockr\weakrefrefexecutor_reference
_processes	processes_call_queuer
_result_queuer|	_work_idswork_ids_queue_max_tasks_per_childmax_tasks_per_child_pending_work_itemsr[r]r)rexecutorrr_s   rrz_ExecutorManagerThread.__init__ s
&EE%44&*%7%7%)%7%7	'#*++h
"C",,#..%22'00$,#@#@ #+">">
rc	|j|j\}}}|r|j|y||j||jdu}|r5|j
j
|j}|j~|jx}rC|r&|j5|jdddn|jj~|jr=|j|j|js|j!y5#1swYYxYwr)add_call_item_to_queuewait_result_broken_or_wakeupterminate_brokenprocess_result_itemrRrrcr)rr\_adjust_process_count_idle_worker_semaphorereleaseis_shutting_downflag_executor_shutting_downr[join_executor_internals)rresult_item	is_brokencauseprocess_exitedprs       rrunz_ExecutorManagerThread.runOs.''),0,M,M,O)KE%%e,&((5!,!5!5T!A!**;+?+?@AFFH #668888%!//=$::<==!77??A $$&002
++-..002Q,==s3D77Ec	|jjry	|jjd}|j|}|j
j
rH|jjt||j|j|jdn|j|=#tj$rYywxYw)NTFr)rfullrrr[rFset_running_or_notify_cancelrzrUrGrHrIqueueEmpty)rrOrhs   rrz-_ExecutorManagerThread.add_call_item_to_queue|s##%
--111>!33G<	##@@BOO''	'2;,,2;..2;2B2B)D/3	(4//8%
;;

sB::CCcX|jj}|jj}||g}t|jjDcgc]}|j}}tjj||z}d}d}d}	||vr	|j}	d}n||vrd}|j5|jj!ddd|	||fScc}w#t$r*}
tt|
|
|
j}Yd}
~
gd}
~
wwxYw#1swYIxYwNTF)r|rr+r&rvaluessentinelr
connectionwaitrecvr{rr;r=r\r)r
result_reader
wakeup_readerreadersrworker_sentinelsreadyrrrrfs           rrz3_ExecutorManagerThread.wait_result_broken_or_wakeups"))11
**22
 -004T^^5J5J5L0MN1AJJNN

""7-=#=>	E!
F+002!	e
#I


	'$$&	'Iu,,'O!
F(a!Q__E
F	'	's*C%C*=D *	D3 DD D)ct|trI|jj|}|j	|js|jyy|jj|jd}|X|jr&|jj|jy|jj|jyyr)
raintrrcr)rr[rOrPrFrd
set_resultrQ)rrrrhs    rrz*_ExecutorManagerThread.process_result_itemsk3'"";/A
FFH>>,,."
//33K4G4GNI$(($$22;3H3HI$$//0B0BC	%rcV|j}txs|duxs|jSr)rr%_shutdown_thread)rrs  rrz'_ExecutorManagerThread.is_shutting_downs4**,
!-H$4-,,	.rc|j}|d|_d|_d}td}|#t	ddj|d|_|jjD]!\}}|jj|~#|jj|jjD]}|j|jj j#|j%y)NzKA child process terminated abruptly, the process pool is not usable anymoreTz^A process in the process pool was terminated abruptly while the future was running or pending.z
'''
r:z''')r_brokenrBrokenProcessPoolr1r)rBr[r(rFrdrrr	terminaterrrr)rrrbperOrhrs       rrz'_ExecutorManagerThread.terminate_brokens**,!1H)-H%H !67,"''%.)-/CM#'"9"9"?"?"A	GY**3/		
%%'&&(	A
KKM	
	
%%'	
$$&rcd|j}|}d|_|jrii}|jj	D]%\}}|j
j
r!|||<'||_		|jjyyy#tj$rYnwxYwd|_$r)rr_cancel_pending_futuresr[r(rFcancelr
get_nowaitrr)rrnew_pending_work_itemsrOrhs     rrz2_ExecutorManagerThread.flag_executor_shutting_downs**,(,H%//*,&*.*A*A*G*G*ID&GY$++224:C.w7D+A'++6680  !;;490s3BB'&B'c,|j}d}||krc|jdkDrOt||z
D]#}	|jjd|dz
}%||kr|jdkDrMyyyy#tj
$rY3wxYw)Nrr.)get_n_children_aliveranger
put_nowaitrFull)rn_children_to_stopn_sentinels_sentis    rshutdown_workersz'_ExecutorManagerThread.shutdown_workerss!668 "44--/!3-0@@A
OO..t4$)$
 "44--/!3535zzs A<<BBc`|j|jj|jj|j5|j
jddd|jjD]}|jy#1swY9xYwr)	rrrjoin_threadr\r+rrr)rrs  rrz._ExecutorManagerThread.join_executor_internals%s##%


	'$$&	'&&(	A
FFH			'	'sB$$B-cVtd|jjDS)Nc3<K|]}|jywr)is_alive).0rs  r	<genexpr>z>_ExecutorManagerThread.get_n_children_alive.<locals>.<genexpr>3sAA1::<As)sumrrrs rrz+_ExecutorManagerThread.get_n_children_alive1s A)>)>)@AAAr)r r!r"rirrrrrrrrrrrrjrks@rrrsD	-^+Z.->D..('T94
Brrctrtrttda	ddl}	tjd}|dk(ry|dk\ryd|zatt#t$rdattwxYw#ttf$rYywxYw)NTrzxThis Python build lacks multiprocessing.synchronize, usually due to named semaphores being unavailable on this platform.SC_SEM_NSEMS_MAXz@system provides too few semaphores (%d available, 256 necessary))	_system_limits_checked_system_limitedNotImplementedErrormultiprocessing.synchronizeImportErrorrsysconfAttributeError
ValueError)multiprocessing	nsems_maxs  r_check_system_limitsr:s%o66!3*JJ12	B	C	46?@O
o
..+3
F	"/223
J'sAA7A47B	B	c#jK|D]*}|j|s|j|r,yw)z
    Specialized implementation of itertools.chain.from_iterable.
    Each item in *iterable* should be a list.  This function is
    careful not to keep references to yielded objects.
    N)reverserc)iterableelements  r_chain_from_iterable_of_listsrZs5 ++- s333ceZdZdZy)rzy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)r r!r"rir#rrrrfsrrceZdZ		ddddZdZdZdZdZdZe	jjje_dd	d
fd
Zddd
dZ
e	jjje
_xZS)ProcessPoolExecutorN)rct|Ptjxsd|_tj
dk(ret
t|j|_nE|dkrtdtj
dk(r|tkDrtdt||_|,|tjd}ntj}||_|jjd	d
k7|_
|t|std||_||_|Ut%|t&std|dkrtd
|jjd	d
k(rtd||_d|_i|_d|_t1j2|_t1j6d|_d|_d|_i|_d|_ tC|_"|jtFz}tI||j|j>|j4|jD|_%d|jJ_&|jO|_(tSjT|_+y)aRInitializes a new ProcessPoolExecutor instance.

        Args:
            max_workers: The maximum number of processes that can be used to
                execute the given calls. If None or not given then as many
                worker processes will be created as the machine has processors.
            mp_context: A multiprocessing context to launch the workers created
                using the multiprocessing.get_context('start method') API. This
                object should provide SimpleQueue, Queue and Process.
            initializer: A callable used to initialize worker processes.
            initargs: A tuple of arguments to pass to the initializer.
            max_tasks_per_child: The maximum number of tasks a worker process
                can complete before it will exit and be replaced with a fresh
                worker process. The default of None means worker process will
                live as long as the executor. Requires a non-'fork' mp_context
                start method. When given, we default to using 'spawn' if no
                mp_context is supplied.
        Nr.win32rz"max_workers must be greater than 0zmax_workers must be <= spawnF)
allow_noneforkzinitializer must be a callablez&max_tasks_per_child must be an integerz max_tasks_per_child must be >= 1zpmax_tasks_per_child is incompatible with the 'fork' multiprocessing start method; supply a different mp_context.)r^rZr[r\r+T),rr	cpu_count_max_workerssysplatformmin_MAX_WINDOWS_WORKERSrrget_context_mp_contextget_start_method#_safe_to_dynamically_spawn_childrencallable	TypeError_initializer	_initargsrarr_executor_manager_threadrr	threadingLockr	Semaphorerr_queue_countrrrrEXTRA_QUEUED_CALLSrXr
_ignore_epipeSimpleQueuerrrr)rmax_workers
mp_contextrrr
queue_sizes       rrzProcessPoolExecutor.__init__nsa(	 " 3!D||w&$'(<(,(9(9%;!a !EFF,,')22 -.B-CDFF!,D".^^G4
^^-
%  11U1CvM	
0"8K+@<=='!*137 HII$) !CDD00E0BfL "CDD%8!)-%!&'nn.&/&9&9!&<##% ',$0=,&&);;
%T%5%5#77-->>	@*.&'335rc|jd|js|jt||_|jj	|j
t|j<yyr)rr
_launch_processesrstartrr'rs r_start_executor_manager_threadz2ProcessPoolExecutor._start_executor_manager_threads`((0;;&&(,B4,HD)))//144
T::;
1rc|jjdryt|j}||jkr|jyy)NF)blocking)racquirelenrr_spawn_process)r
process_counts  rrz)ProcessPoolExecutor._adjust_process_countsK&&...>DOO,
4,,,
!-rctt|j|jD]}|j	yr)rr$rrr%)rr*s  rrz%ProcessPoolExecutor._launch_processess5
s4??+T->->?	"A!	"rc|jjt|j|j|j
|j|jf}|j||j|j<y)N)targetrH)rProcessrrrrrrrrpidrs  rr%z"ProcessPoolExecutor._spawn_processsm$$"""$$##..++	-
%
.	
	!"rcR|j5|jrt|j|jrt	dt
rt	dt
j}t||||}||j|j<|jj|j|xjdz
c_
|jj|jr|j!|j#|cdddS#1swYyxYw)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdownr.)rrrrRuntimeErrorr%rFuturerDrrrrzrrr
rr )rrGrHrIfws      rsubmitzProcessPoolExecutor.submits

 
 	||'55$$"#OPP"$:;;A!Rv.A:;D$$T%6%67NNt001"0077977**,//1+			sDDD&r.)timeoutrqc|dkrtdt|	tt|t|d|i|}t
|S)ajReturns an iterator equivalent to map(fn, iter).

        Args:
            fn: A callable that will take as many arguments as there are
                passed iterables.
            timeout: The maximum number of seconds to wait. If None, then there
                is no limit on the wait time.
            chunksize: If greater than one, the iterables will be chopped into
                chunks of size chunksize and submitted to the process pool.
                If set to one, the items in the list will be sent one at a time.

        Returns:
            An iterator equivalent to: map(func, *iterables) but the calls may
            be evaluated out-of-order.

        Raises:
            TimeoutError: If the entire result iterator could not be generated
                before the given timeout.
            Exception: If fn(*args) raises for any values.
        r.zchunksize must be >= 1.rq)r2)rr]maprrwrur)rrGr2rqrrresultsr_s      rr4zProcessPoolExecutor.mapsQ*q=677'+gnb9)9J	J&-/-W55rF)cancel_futuresc|j5||_d|_|j|jj	ddd|j
|r|j
j
d|_d|_|j|r|jjd|_d|_
d|_y#1swY}xYwr)rrrrrrr)rrrr)rrr6s   rshutdownzProcessPoolExecutor.shutdown;s

 
 	>+9D($(D!33?44;;=	>((4))..0)-%)d$$&!/3,#	>	>s5B>>C)NNNr#)T)r r!r"rr rrr%r1rExecutorrir4r8rjrks@rrrms~48,.i'GKi'V5
""	#.^^**22FN*.!6:4E4(~~..66HrrrSr)2ri
__author__rconcurrent.futuresrrrrmultiprocessing.connectionmultiprocessing.queuesrrr	functoolsrror	tracebackrWeakKeyDictionaryr'r%rr-_register_atexitrr		Exceptionr1r8r?objectrDrMrUrXrurwr}rThreadrrrrrBrokenExecutorrr9rr#rr<module>rFs?(T2
	$"(
&-7,,.***	<(y	1	1!&!332	)DH"	93l_BY--_BD	/@	 ,,b7%..b7r