AlkantarClanX12

Your IP : 3.16.82.208


Current Path : /opt/alt/python39/lib64/python3.9/concurrent/futures/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/concurrent/futures/__pycache__/process.cpython-39.pyc

a

R�f�z�@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�?/opt/alt/python39/lib64/python3.9/concurrent/futures/process.py�__init__Csz_ThreadWakeup.__init__cCs$|js d|_|j��|j��dS�NT)rr	�closerr
rrr
rGs
z_ThreadWakeup.closecCs|js|j�d�dS)N�)rr	Z
send_bytesr
rrr
�wakeupMsz_ThreadWakeup.wakeupcCs |js|j��r|j��qdS�N)rrZpollZ
recv_bytesr
rrr
�clearQs
z_ThreadWakeup.clearN)�__name__�
__module__�__qualname__rrrrrrrr
rBsrcCs@datt���}|D]\}}|��q|D]\}}|��q*dSr)�_global_shutdown�list�_threads_wakeups�itemsr�join)r�_�
thread_wakeup�trrr
�_python_exitWs
r ��=c@seZdZdd�Zdd�ZdS)�_RemoteTracebackcCs
||_dSr��tb)rr%rrr
rwsz_RemoteTraceback.__init__cCs|jSrr$r
rrr
�__str__ysz_RemoteTraceback.__str__N)rrrrr&rrrr
r#vsr#c@seZdZdd�Zdd�ZdS)�_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)rrrrr/rrrr
r'|sr'cCst|�|_|Sr)r#�	__cause__)r,r%rrr
r.�s
r.c@seZdZdd�ZdS)�	_WorkItemcCs||_||_||_||_dSr)�future�fn�args�kwargs)rr2r3r4r5rrr
r�sz_WorkItem.__init__N�rrrrrrrr
r1�sr1c@seZdZddd�ZdS)�_ResultItemNcCs||_||_||_dSr)�work_id�	exception�result)rr8r9r:rrr
r�sz_ResultItem.__init__)NNr6rrrr
r7�sr7c@seZdZdd�ZdS)�	_CallItemcCs||_||_||_||_dSr)r8r3r4r5)rr8r3r4r5rrr
r�sz_CallItem.__init__Nr6rrrr
r;�sr;cs.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_sizer=r>r?r��	__class__rr
r�sz_SafeQueue.__init__cs�t|t�r�t�t|�||j�}td�d�|���|_	|j
�|jd�}|j
�|j��Wd�n1sj0Y|dur�|j�|�nt��||�dS)Nz

"""
{}"""r()�
isinstancer;r)r*r+r-r#�formatrr0r>�popr8r?rrr2�
set_exceptionr@�_on_queue_feeder_error)r�e�objr%�	work_itemrBrr
rH�s
(z!_SafeQueue._on_queue_feeder_error)r)rrr�__doc__rrH�
__classcell__rrrBr
r<�sr<cgs,t|�}tt�||��}|s dS|VqdS)z, Iterates over zip()ed iterables in chunks. N)�zip�tuple�	itertools�islice)�	chunksize�	iterables�it�chunkrrr
�_get_chunks�s
rVcs�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)�.0r4�r3rr
�
<listcomp>�rz"_process_chunk.<locals>.<listcomp>r)r3rUrrXr
�_process_chunk�s	rZc
Cs`z|�t|||d��WnBtyZ}z*t||j�}|�t||d��WYd}~n
d}~00dS)z.Safely send back the given result or exception)r:r9�r9N)�putr7�
BaseExceptionr'r-)�result_queuer8r:r9rIr,rrr
�_sendback_result�s
�r_c
Cs�|dur:z||�Wn$ty8tjjddd�YdS0|jdd�}|dur`|�t���dSz|j|j	i|j
��}Wn@ty�}z(t||j�}t
||j|d�WYd}~nd}~00t
||j|d�~~q:dS)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��blockr[)r:)r]rZLOGGERZcritical�getr\�os�getpidr3r4r5r'r-r_r8)�
call_queuer^�initializer�initargsZ	call_item�rrIr,rrr
�_process_worker�s$
&rjcspeZdZdZ�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�n1s.0YdS)Nz?Executor collected: triggering callback for QueueManager wakeup)r�util�debugr)rrr?rrr
�
weakref_cbsz3_ExecutorManagerThread.__init__.<locals>.weakref_cb)�_executor_manager_thread_wakeupr�_shutdown_lockr?�weakref�ref�executor_reference�
_processes�	processes�_call_queuerf�
_result_queuer^�	_work_ids�work_ids_queue�_pending_work_itemsr>r@r)r�executorrnrBrr
rs	�
z_ExecutorManagerThread.__init__cCs�|��|��\}}}|r(|�|�dS|durX|�|�~|��}|durV|j��~|��r|��|j	s|�
�dSqdSr)�add_call_item_to_queue�wait_result_broken_or_wakeup�terminate_broken�process_result_itemrs�_idle_worker_semaphore�release�is_shutting_down�flag_executor_shutting_downr>�join_executor_internals)r�result_item�	is_broken�causer{rrr
�run:s"


z_ExecutorManagerThread.runcCs~|j��rdSz|jjdd�}Wntjy6YdS0|j|}|j��rn|jj	t
||j|j|j
�dd�q|j|=qqdS)NFraT)rfZfullryrc�queue�Emptyr>r2Zset_running_or_notify_cancelr\r;r3r4r5)rr8rKrrr
r|Zs"



��z-_ExecutorManagerThread.add_call_item_to_queuec

Cs�|jj}|jjrJ�|jj}||g}dd�t|j���D�}tj�	||�}d}d}d}||vr�z|�
�}d}Wq�ty�}	z t�
t|	�|	|	j�}WYd}	~	q�d}	~	00n||vr�d}|j�|j��Wd�n1s�0Y|||fS)NcSsg|]
}|j�qSr)�sentinel�rW�prrr
rY{rzG_ExecutorManagerThread.wait_result_broken_or_wakeup.<locals>.<listcomp>TF)r^rrrrru�valuesrZ
connection�waitZrecvr]r)r*r+r-r?r)
rZ
result_readerZ
wakeup_readerZreadersZworker_sentinelsZreadyr�r�r�rIrrr
r}qs(,(z3_ExecutorManagerThread.wait_result_broken_or_wakeupcCs~t|t�r>|��sJ�|j�|�}|��|jsz|��dSn<|j�|jd�}|durz|j	rl|j
�|j	�n|j
�|j
�dSr)rD�intr�rurFrr�r>r8r9r2rGZ
set_resultr:)rr�r�rKrrr
r�s
z*_ExecutorManagerThread.process_result_itemcCs|��}tp|dup|jSr)rsr�_shutdown_thread)rr{rrr
r��s�z'_ExecutorManagerThread.is_shutting_downcCs�|��}|dur d|_d|_d}td�}|durHtdd�|��d��|_|j��D]\}}|j	�
|�~qR|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''')rs�_brokenr��BrokenProcessPoolr#rr0r>rr2rGrrur�Z	terminater�)rr�r{Zbper8rKr�rrr
r~�s"�

z'_ExecutorManagerThread.terminate_brokencCs�|��}|dur|d|_|jr|i}|j��D]\}}|j��s*|||<q*||_z|j��WqLt	j
yrYqvYqL0qLd|_dS)NTF)rsr��_cancel_pending_futuresr>rr2ZcancelryZ
get_nowaitr�r�)rr{Znew_pending_work_itemsr8rKrrr
r��s

z2_ExecutorManagerThread.flag_executor_shutting_downc	Csl|��}d}||krh|��dkrht||�D]8}z|j�d�|d7}Wq,tjybYqYq,0q,qdS)Nrr!)�get_n_children_alive�rangerfZ
put_nowaitr�ZFull)rZn_children_to_stopZn_sentinels_sent�irrr
�shutdown_workers�s
�z'_ExecutorManagerThread.shutdown_workerscCsh|��|j��|j��|j�|j��Wd�n1sB0Y|j��D]}|��qVdSr)	r�rfrZjoin_threadr?rrur�r�rr�rrr
r��s

(z._ExecutorManagerThread.join_executor_internalscCstdd�|j��D��S)Ncss|]}|��VqdSr)Zis_aliver�rrr
�	<genexpr>
rz>_ExecutorManagerThread.get_n_children_alive.<locals>.<genexpr>)�sumrur�r
rrr
r�sz+_ExecutorManagerThread.get_n_children_alive)rrrrLrr�r|r}rr�r~r�r�r�r�rMrrrBr
rks+ 
&rkc	Cshtrtrtt��dazt�d�}Wnttfy:YdS0|dkrHdS|dkrTdSd|att��dS)NT�SC_SEM_NSEMS_MAX����z@system provides too few semaphores (%d available, 256 necessary))�_system_limits_checked�_system_limited�NotImplementedErrorrd�sysconf�AttributeError�
ValueError)Z	nsems_maxrrr
�_check_system_limitss �r�ccs&|D]}|��|r|��VqqdS)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)�reverserF)�iterableZelementrrr
�_chain_from_iterable_of_lists,sr�c@seZdZdZdS)r�zy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)rrrrLrrrr
r�8sr�cs~eZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Ze	j
jje_ddd��fdd�
Zddd�dd�Z
e	j
j
je
_�ZS)�ProcessPoolExecutorNrcCsJt�|dur6t��pd|_tjdkrntt|j�|_n8|dkrHtd��n tjdkrh|tkrhtdt����||_|dur~t	�
�}||_|jjdd�d	k|_
|dur�t|�s�td
��||_||_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)rAr=r>r?rT))r�rd�	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_threadrtr��	threadingZLockrpZ	Semaphorer�r��_queue_countrzr�rro�EXTRA_QUEUED_CALLSr<rvZ
_ignore_epipeZSimpleQueuerwr�rrx)rZmax_workersZ
mp_contextrgrhZ
queue_sizerrr
r@sZ

�

���


�
zProcessPoolExecutor.__init__cCs<|jdur8|js|��t|�|_|j��|jt|j<dSr)r�r��_launch_processesrk�startrorr
rrr
�_start_executor_manager_thread�s


�z2ProcessPoolExecutor._start_executor_manager_threadcCs2|jjdd�rdSt|j�}||jkr.|��dS)NF)Zblocking)r��acquire�lenrtr��_spawn_process)rZ
process_countrrr
�_adjust_process_count�s


z)ProcessPoolExecutor._adjust_process_countcCs2|jrJd��tt|j�|j�D]}|��q dS)NzhProcesses cannot be fork()ed after the thread has started, deadlock in the child processes could result.)r�r�r�rtr�r�)rrrrr
r��s
�z%ProcessPoolExecutor._launch_processescCs8|jjt|j|j|j|jfd�}|��||j|j	<dS)N)�targetr4)
r�ZProcessrjrvrwr�r�r�rt�pidr�rrr
r��s��z"ProcessPoolExecutor._spawn_processcOs�|j��|jrt|j��|jr&td��tr2td��t��}t||||�}||j	|j
<|j�|j
�|j
d7_
|j
��|jr�|��|��|Wd�S1s�0YdS)Nz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdownr!)rpr�r�r��RuntimeErrorrrZFuturer1rzr�rxr\rorr�r�r�)rr3r4r5�f�wrrr
�submit�s"

zProcessPoolExecutor.submitr!)�timeoutrRcs:|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.rR)r�)r�r@�maprrZrVr�)rr3r�rRrSZresultsrBrr
r��s�zProcessPoolExecutor.mapTF)�cancel_futurescCs�|j�0||_d|_|jdur(|j��Wd�n1s<0Y|jdur^|r^|j��d|_d|_|jdur�|r�|j�	�d|_d|_
d|_dSr)rpr�r�rorr�rrvrwrrt)rr�r�rrr
�shutdown�s
(

zProcessPoolExecutor.shutdown)NNNr)T)rrrrr�r�r�r�r�r�ExecutorrLr�r�rMrrrBr
r�?s�
U

r�)NN)1rL�
__author__rdZconcurrent.futuresrr�ZmultiprocessingrZmultiprocessing.connectionZmultiprocessing.queuesrr�rq�	functoolsrrPr�r)�WeakKeyDictionaryrrrr Z_register_atexitr�r��	Exceptionr#r'r.�objectr1r7r;r<rVrZr_rjZThreadrkr�r�r�r�ZBrokenExecutorr�r�r�rrrr
�<module>sP*



)