Your IP : 3.144.18.59


Current Path : /opt/alt/python310/lib64/python3.10/concurrent/futures/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/concurrent/futures/__pycache__/process.cpython-310.opt-1.pyc

o

6��f�|�@s�dZdZddlZddlmZddlZddlZddlZddl	m
Z
ddlZddlZddl
mZddlZddlZddlZe��ZdaGdd	�d	�Zd
d�Ze�e�dZd
ZGdd�de�ZGdd�d�Zdd�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de
�Z"dd�Z#dd�Z$d.d d!�Z%d"d#�Z&Gd$d%�d%ej'�Z(da)da*d&d'�Z+d(d)�Z,Gd*d+�d+ej-�Z.Gd,d-�d-ej/�Z0dS)/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)�partialFc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
_ThreadWakeupcCsd|_tjdd�\|_|_dS)NF)Zduplex)�_closed�mpZPipe�_reader�_writer��self�r�A/opt/alt/python310/lib64/python3.10/concurrent/futures/process.py�__init__Csz_ThreadWakeup.__init__cCs(|jsd|_|j��|j��dSdS�NT)rr	�closerr
rrr
rGs

�z_ThreadWakeup.closecCs|js|j�d�dSdS)N�)rr	Z
send_bytesr
rrr
�wakeupMs�z_ThreadWakeup.wakeupcCs0|js|j��r|j��|j��sdSdSdS�N)rrZpollZ
recv_bytesr
rrr
�clearQs

��z_ThreadWakeup.clearN)�__name__�
__module__�__qualname__rrrrrrrr
rBs
rcCs@datt���}|D]\}}|��q
|D]\}}|��qdSr)�_global_shutdown�list�_threads_wakeups�itemsr�join)r�_�
thread_wakeup�trrr
�_python_exitWs

�r ��=c@�eZdZdd�Zdd�ZdS)�_RemoteTracebackcCs
||_dSr��tb)rr&rrr
rws
z_RemoteTraceback.__init__cCs|jSrr%r
rrr
�__str__ysz_RemoteTraceback.__str__N)rrrrr'rrrr
r$vsr$c@r#)�_ExceptionWithTracebackcCs8t�t|�||�}d�|�}||_d|j_d||_dS)N�z

"""
%s""")�	traceback�format_exception�typer�exc�
__traceback__r&)rr-r&rrr
r}s

z _ExceptionWithTraceback.__init__cCst|j|jffSr)�_rebuild_excr-r&r
rrr
�
__reduce__�sz"_ExceptionWithTraceback.__reduce__N)rrrrr0rrrr
r(|sr(cCst|�|_|Sr)r$�	__cause__)r-r&rrr
r/�s
r/c@�eZdZdd�ZdS)�	_WorkItemcC�||_||_||_||_dSr)�future�fn�args�kwargs)rr5r6r7r8rrr
r��
z_WorkItem.__init__N�rrrrrrrr
r3��r3c@seZdZddd�ZdS)�_ResultItemNcCs||_||_||_dSr)�work_id�	exception�result)rr=r>r?rrr
r�s
z_ResultItem.__init__�NNr:rrrr
r<�sr<c@r2)�	_CallItemcCr4r)r=r6r7r8)rr=r6r7r8rrr
r�r9z_CallItem.__init__Nr:rrrr
rA�r;rAcs.eZdZdZd�fdd�	Z�fdd�Z�ZS)�
_SafeQueuez=Safe Queue set exception to the future object linked to a jobrcs&||_||_||_t�j||d�dS)N)�ctx)�pending_work_items�
shutdown_lockr�superr)r�max_sizerCrDrEr��	__class__rr
r�sz_SafeQueue.__init__cs�t|t�rHt�t|�||j�}td�d�|���|_	|j
�|jd�}|j
�
|j��Wd�n1s5wY|durF|j�|�dSdSt��||�dS)Nz

"""
{}"""r))�
isinstancerAr*r+r,r.r$�formatrr1rD�popr=rErrr5�
set_exceptionrF�_on_queue_feeder_error)r�e�objr&�	work_itemrHrr
rN�s
��z!_SafeQueue._on_queue_feeder_error)r)rrr�__doc__rrN�
__classcell__rrrHr
rB�srBcgs,�t|�}	tt�||��}|sdS|Vq)z, Iterates over zip()ed iterables in chunks. TN)�zip�tuple�	itertools�islice)�	chunksize�	iterables�it�chunkrrr
�_get_chunks�s��r\cs�fdd�|D�S)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.

    csg|]}�|��qSrr)�.0r7�r6rr
�
<listcomp>�sz"_process_chunk.<locals>.<listcomp>r)r6r[rr^r
�_process_chunk�s	r`c
Cs`z
|�t|||d��WdSty/}zt||j�}|�t||d��WYd}~dSd}~ww)z.Safely send back the given result or exception)r?r>�r>N)�putr<�
BaseExceptionr(r.)�result_queuer=r?r>rOr-rrr
�_sendback_result�s
� ��rec
Cs�|durz||�Wntytjjddd�YdSw	|jdd�}|dur1|�t���dSz|j|j	i|j
��}Wn ty]}zt||j�}t
||j|d�WYd}~nd}~wwt
||j|d�~~q)a�Evaluates 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_info��blockra)r?)rcrZLOGGERZcritical�getrb�os�getpidr6r7r8r(r.rer=)�
call_queuerd�initializer�initargsZ	call_item�rrOr-rrr
�_process_worker�s.
����rpcspeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Z�ZS)�_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.
    csf|j|_|j|_|j|jfdd�}t�||�|_|j|_|j	|_
|j|_|j
|_|j|_t���dS)NcSs>tj�d�|�
|��Wd�dS1swYdS)Nz?Executor collected: triggering callback for QueueManager wakeup)r�util�debugr)rrrErrr
�
weakref_cbs
"�z3_ExecutorManagerThread.__init__.<locals>.weakref_cb)�_executor_manager_thread_wakeupr�_shutdown_lockrE�weakref�ref�executor_reference�
_processes�	processes�_call_queuerl�
_result_queuerd�	_work_ids�work_ids_queue�_pending_work_itemsrDrFr)r�executorrtrHrr
rs	
�z_ExecutorManagerThread.__init__cCs�	|��|��\}}}|r|�|�dS|dur-|�|�~|��}|dur,|j��~|��rB|��|��|j	sB|�
�dSqr)�add_call_item_to_queue�wait_result_broken_or_wakeup�terminate_broken�process_result_itemry�_idle_worker_semaphore�release�is_shutting_down�flag_executor_shutting_downrD�join_executor_internals)r�result_item�	is_broken�causer�rrr
�run:s(


�z_ExecutorManagerThread.runcCs|	|j��rdSz	|jjdd�}WntjyYdSw|j|}|j��r8|jj	t
||j|j|j
�dd�n|j|=qq)NTFrg)rlZfullrri�queue�EmptyrDr5Zset_running_or_notify_cancelrbrAr6r7r8)rr=rQrrr
r�_s(
�


���z-_ExecutorManagerThread.add_call_item_to_queuec

Cs�|jj}|jj}||g}dd�t|j���D�}tj�||�}d}d}d}||vrOz|�	�}d}Wn"t
yN}	zt�t
|	�|	|	j�}WYd}	~	nd}	~	ww||vrUd}|j�
|j��Wd�n1shwY|||fS)NcSsg|]}|j�qSr)Zsentinel�r]�prrr
r_�szG_ExecutorManagerThread.wait_result_broken_or_wakeup.<locals>.<listcomp>TF)rdrrrr{�valuesrZ
connection�waitZrecvrcr*r+r,r.rEr)
rZ
result_readerZ
wakeup_readerZreadersZworker_sentinelsZreadyr�r�r�rOrrr
r�vs, ���
z3_ExecutorManagerThread.wait_result_broken_or_wakeupcCszt|t�r|j�|�}|��|js|��dSdS|j�|jd�}|dur;|jr2|j	�
|j�dS|j	�|j�dSdSr)
rJ�intr{rLrr�rDr=r>r5rMZ
set_resultr?)rr�r�rQrrr
r��s
��z*_ExecutorManagerThread.process_result_itemcCs|��}tp|dup|jSr)ryr�_shutdown_thread)rr�rrr
r��s�z'_ExecutorManagerThread.is_shutting_downcCs�|��}|durd|_d|_d}td�}|dur$tdd�|��d��|_|j��D]\}}|j	�
|�~q)|j��|j�
�D]}|��q?|��dS)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''')ry�_brokenr��BrokenProcessPoolr$rr1rDrr5rMrr{r�Z	terminater�)rr�r�Zbper=rQr�rrr
r��s"�

z'_ExecutorManagerThread.terminate_brokencCs�|��}|dur?d|_|jrAi}|j��D]
\}}|j��s"|||<q||_	z|j��Wn
t	j
y8Ynwq'd|_dSdSdS)NTF)ryr��_cancel_pending_futuresrDrr5ZcancelrZ
get_nowaitr�r�)rr�Znew_pending_work_itemsr=rQrrr
r��s(
���
�z2_ExecutorManagerThread.flag_executor_shutting_downc	Cs�|��}d}||kr<|��dkr>t||�D]}z|j�d�|d7}Wqtjy/Ynw||kr@|��dksdSdSdSdS)Nrr!)�get_n_children_alive�rangerlZ
put_nowaitr�ZFull)rZn_children_to_stopZn_sentinels_sent�irrr
�shutdown_workers�s ����z'_ExecutorManagerThread.shutdown_workerscCsh|��|j��|j��|j�
|j��Wd�n1s!wY|j��D]}|��q+dSr)	r�rlrZjoin_threadrErr{r�r�rr�rrr
r�s

�
�z._ExecutorManagerThread.join_executor_internalscCstdd�|j��D��S)Ncss�|]}|��VqdSr)Zis_aliver�rrr
�	<genexpr>s�z>_ExecutorManagerThread.get_n_children_alive.<locals>.<genexpr>)�sumr{r�r
rrr
r�sz+_ExecutorManagerThread.get_n_children_alive)rrrrRrr�r�r�r�r�r�r�r�r�r�rSrrrHr
rqs+%
&rqc	Cs�trtrtt��dazddl}Wn
tydatt��wzt�d�}Wnttfy1YdSw|dkr8dS|dkr>dSd|att��)NTrzxThis Python build lacks multiprocessing.synchronize, usually due to named semaphores being unavailable on this platform.�SC_SEM_NSEMS_MAX����z@system provides too few semaphores (%d available, 256 necessary))	�_system_limits_checked�_system_limited�NotImplementedErrorZmultiprocessing.synchronize�ImportErrorrj�sysconf�AttributeError�
ValueError)�multiprocessingZ	nsems_maxrrr
�_check_system_limitss0����r�ccs*�|D]}|��|r|��V|sqdS)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)�reverserL)�iterableZelementrrr
�_chain_from_iterable_of_lists9s�
���r�c@seZdZdZdS)r�zy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)rrrrRrrrr
r�Esr�cs�eZdZ		ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Ze	j
jje_ddd��fdd�
Zddd�dd�Z
e	j
j
je
_�ZS)�ProcessPoolExecutorNrcCsHt�|durt��pd|_tjdkrtt|j�|_n|dkr#td��tjdkr3|tkr3tdt����||_|dur>t	�
�}||_|jjdd�d	k|_
|durWt|�sWtd
��||_||_d|_i|_d|_t��|_t�d�|_d|_d|_i|_d|_t�|_|jt }t!||j|j|j|jd�|_"d|j"_#|�$�|_%t&�'�|_(dS)
aSInitializes 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. 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.
        Nr!Zwin32rz"max_workers must be greater than 0zmax_workers must be <= F)Z
allow_none�forkzinitializer must be a callable)rGrCrDrErT))r�rj�	cpu_count�_max_workers�sys�platform�min�_MAX_WINDOWS_WORKERSr�rZget_context�_mp_contextZget_start_method�#_safe_to_dynamically_spawn_children�callable�	TypeError�_initializer�	_initargs�_executor_manager_threadrzr��	threadingZLockrvZ	Semaphorer�r��_queue_countr�r�rru�EXTRA_QUEUED_CALLSrBr|Z
_ignore_epipeZSimpleQueuer}r�rr~)rZmax_workersZ
mp_contextrmrnZ
queue_sizerrr
rMsZ

��
��


�
zProcessPoolExecutor.__init__cCs@|jdur|js|��t|�|_|j��|jt|j<dSdSr)r�r��_launch_processesrq�startrurr
rrr
�_start_executor_manager_thread�s


��z2ProcessPoolExecutor._start_executor_manager_threadcCs6|jjdd�r	dSt|j�}||jkr|��dSdS)NF)Zblocking)r��acquire�lenrzr��_spawn_process)rZ
process_countrrr
�_adjust_process_count�s

�z)ProcessPoolExecutor._adjust_process_countcCs$tt|j�|j�D]}|��q	dSr)r�r�rzr�r�)rrrrr
r��s
�z%ProcessPoolExecutor._launch_processescCs8|jjt|j|j|j|jfd�}|��||j|j	<dS)N)�targetr7)
r�ZProcessrpr|r}r�r�r�rz�pidr�rrr
r��s��z"ProcessPoolExecutor._spawn_processcOs�|j�N|jrt|j��|jrtd��trtd��t��}t||||�}||j	|j
<|j�|j
�|j
d7_
|j
��|jrD|��|��|Wd�S1sTwYdS)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdownr!)rvr�r�r��RuntimeErrorrrZFuturer3r�r�r~rbrurr�r�r�)rr6r7r8�f�wrrr
�submit�s$

$�zProcessPoolExecutor.submitr!)�timeoutrXcs:|dkrtd��t�jtt|�t|d|i�|d�}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.rX)r�)r�rF�maprr`r\r�)rr6r�rXrYZresultsrHrr
r��s�zProcessPoolExecutor.mapTF)�cancel_futurescCs�|j�||_d|_|jdur|j��Wd�n1swY|jdur/|r/|j��d|_d|_|jdurA|rA|j�	�d|_d|_
d|_dSr)rvr�r�rurr�rr|r}rrz)rr�r�rrr
�shutdowns 

��


zProcessPoolExecutor.shutdown)NNNr)T)rrrrr�r�r�r�r�r�ExecutorrRr�r�rSrrrHr
r�Ls
�U

r�r@)1rR�
__author__rjZconcurrent.futuresrr�r�rZmultiprocessing.connectionZmultiprocessing.queuesrr�rw�	functoolsrrVr�r*�WeakKeyDictionaryrrrr Z_register_atexitr�r��	Exceptionr$r(r/�objectr3r<rArBr\r`rerpZThreadrqr�r�r�r�ZBrokenExecutorr�r�r�rrrr
�<module>sR*



) 

?>