Mini Shell

Direktori : /usr/lib64/python3.9/concurrent/futures/__pycache__/
Upload File :
Current File : //usr/lib64/python3.9/concurrent/futures/__pycache__/process.cpython-39.pyc

a

�DOg�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)�duplex)�_closed�mp�Pipe�_reader�_writer��self�r�2/usr/lib64/python3.9/concurrent/futures/process.py�__init__Csz_ThreadWakeup.__init__cCs$|js d|_|j��|j��dS�NT)rr�closer
rrrrrGs
z_ThreadWakeup.closecCs|js|j�d�dS)N�)rr�
send_bytesrrrr�wakeupMsz_ThreadWakeup.wakeupcCs |js|j��r|j��qdS�N)rr
�poll�
recv_bytesrrrr�clearQs
z_ThreadWakeup.clearN)�__name__�
__module__�__qualname__rrrrrrrrrBsrcCs@datt���}|D]\}}|��q|D]\}}|��q*dSr)�_global_shutdown�list�_threads_wakeups�itemsr�join)r �_�
thread_wakeup�trrr�_python_exitWs
r%��=c@seZdZdd�Zdd�ZdS)�_RemoteTracebackcCs
||_dSr��tb)r
r*rrrrwsz_RemoteTraceback.__init__cCs|jSrr)rrrr�__str__ysz_RemoteTraceback.__str__N)rrrrr+rrrrr(vsr(c@seZdZdd�Zdd�ZdS)�_ExceptionWithTracebackcCs8t�t|�||�}d�|�}||_d|j_d||_dS)N�z

"""
%s""")�	traceback�format_exception�typer!�exc�
__traceback__r*)r
r1r*rrrr}s

z _ExceptionWithTraceback.__init__cCst|j|jffSr)�_rebuild_excr1r*rrrr�
__reduce__�sz"_ExceptionWithTraceback.__reduce__N)rrrrr4rrrrr,|sr,cCst|�|_|Sr)r(�	__cause__)r1r*rrrr3�s
r3c@seZdZdd�ZdS)�	_WorkItemcCs||_||_||_||_dSr)�future�fn�args�kwargs)r
r7r8r9r:rrrr�sz_WorkItem.__init__N�rrrrrrrrr6�sr6c@seZdZddd�ZdS)�_ResultItemNcCs||_||_||_dSr)�work_id�	exception�result)r
r=r>r?rrrr�sz_ResultItem.__init__)NNr;rrrrr<�sr<c@seZdZdd�ZdS)�	_CallItemcCs||_||_||_||_dSr)r=r8r9r:)r
r=r8r9r:rrrr�sz_CallItem.__init__Nr;rrrrr@�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_sizerBrCrDr#��	__class__rrr�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/r0r2r(�formatr!r5rC�popr=rDr#rr7�
set_exceptionrE�_on_queue_feeder_error)r
�e�objr*�	work_itemrGrrrM�s
(z!_SafeQueue._on_queue_feeder_error)r)rrr�__doc__rrM�
__classcell__rrrGrrA�srAcgs,t|�}tt�||��}|s dS|VqdS)z, Iterates over zip()ed iterables in chunks. N)�zip�tuple�	itertools�islice)�	chunksize�	iterables�it�chunkrrr�_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|]}�|��qSrr)�.0r9�r8rr�
<listcomp>�rz"_process_chunk.<locals>.<listcomp>r)r8rZrr]r�_process_chunk�s	r_c
Cs`z|�t|||d��WnBtyZ}z*t||j�}|�t||d��WYd}~n
d}~00dS)z.Safely send back the given result or exception)r?r>�r>N)�putr<�
BaseExceptionr,r2)�result_queuer=r?r>rNr1rrr�_sendback_result�s
�rdc
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?)rbr�LOGGER�critical�getra�os�getpidr8r9r:r,r2rdr=)�
call_queuerc�initializer�initargs�	call_item�rrNr1rrr�_process_worker�s$
&rrcspeZdZdZ�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)r"r#rDrrr�
weakref_cbsz3_ExecutorManagerThread.__init__.<locals>.weakref_cb)�_executor_manager_thread_wakeupr#�_shutdown_lockrD�weakref�ref�executor_reference�
_processes�	processes�_call_queuerm�
_result_queuerc�	_work_ids�work_ids_queue�_pending_work_itemsrCrEr)r
�executorrvrGrrrs	�
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_itemr{�_idle_worker_semaphore�release�is_shutting_down�flag_executor_shutting_downrC�join_executor_internals)r
�result_item�	is_broken�causer�rrr�run:s"


z_ExecutorManagerThread.runcCs~|j��rdSz|jjdd�}Wntjy6YdS0|j|}|j��rn|jj	t
||j|j|j
�dd�q|j|=qqdS)NFrfT)rm�fullr�rj�queue�EmptyrCr7�set_running_or_notify_cancelrar@r8r9r:)r
r=rPrrrr�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�r\�prrrr^{rzG_ExecutorManagerThread.wait_result_broken_or_wakeup.<locals>.<listcomp>TF)rcr
r#rrr}�valuesr�
connection�wait�recvrbr.r/r0r2rDr)
r
�
result_reader�
wakeup_reader�readers�worker_sentinels�readyr�r�r�rNrrrr�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)rI�intr�r}rKr!r�rCr=r>r7rL�
set_resultr?)r
r�r�rPrrrr��s
z*_ExecutorManagerThread.process_result_itemcCs|��}tp|dup|jSr)r{r�_shutdown_thread)r
r�rrrr��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''')r{�_brokenr��BrokenProcessPoolr(r!r5rCr r7rLrr}r��	terminater�)r
r�r��bper=rPr�rrrr��s"�

z'_ExecutorManagerThread.terminate_brokencCs�|��}|dur|d|_|jr|i}|j��D]\}}|j��s*|||<q*||_z|j��WqLt	j
yrYqvYqL0qLd|_dS)NTF)r{r��_cancel_pending_futuresrCr r7�cancelr��
get_nowaitr�r�)r
r��new_pending_work_itemsr=rPrrrr��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�rangerm�
put_nowaitr��Full)r
�n_children_to_stop�n_sentinels_sent�irrr�shutdown_workers�s
�z'_ExecutorManagerThread.shutdown_workerscCsh|��|j��|j��|j�|j��Wd�n1sB0Y|j��D]}|��qVdSr)	r�rmr�join_threadrDr#r}r�r!�r
r�rrrr��s

(z._ExecutorManagerThread.join_executor_internalscCstdd�|j��D��S)Ncss|]}|��VqdSr)�is_aliver�rrr�	<genexpr>
rz>_ExecutorManagerThread.get_n_children_alive.<locals>.<genexpr>)�sumr}r�rrrrr�sz+_ExecutorManagerThread.get_n_children_alive)rrrrQrr�r�r�r�r�r�r�r�r�r�rRrrrGrrss+ 
&rsc	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�NotImplementedErrorrk�sysconf�AttributeError�
ValueError)�	nsems_maxrrr�_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)�reverserK)�iterable�elementrrr�_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)rrrrQrrrrr�8sr�cs~eZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Ze	j
jje_ddd��fdd�
Zddd�dd�Z
e	j
j
je
_�ZS)�ProcessPoolExecutorNrcCsJt�|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&�win32rz"max_workers must be greater than 0zmax_workers must be <= F)�
allow_none�forkzinitializer must be a callable)rFrBrCrDr#T))r�rk�	cpu_count�_max_workers�sys�platform�min�_MAX_WINDOWS_WORKERSr�r�get_context�_mp_context�get_start_method�#_safe_to_dynamically_spawn_children�callable�	TypeError�_initializer�	_initargs�_executor_manager_threadr|r��	threading�Lockrx�	Semaphorer�r��_queue_countr�r�rrw�EXTRA_QUEUED_CALLSrAr~�
_ignore_epipe�SimpleQueuerr�rr�)r
�max_workers�
mp_contextrnro�
queue_sizerrrr@sZ

�

���


�
zProcessPoolExecutor.__init__cCs<|jdur8|js|��t|�|_|j��|jt|j<dSr)r�r��_launch_processesrs�startrwrrrrr�_start_executor_manager_thread�s


�z2ProcessPoolExecutor._start_executor_manager_threadcCs2|jjdd�rdSt|j�}||jkr.|��dS)NF)�blocking)r��acquire�lenr|r��_spawn_process)r
�
process_countrrr�_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�r|r�r�)r
r"rrrr��s
�z%ProcessPoolExecutor._launch_processescCs8|jjt|j|j|j|jfd�}|��||j|j	<dS)N)�targetr9)
r��Processrrr~rr�r�r�r|�pidr�rrrr��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&)rxr�r�r��RuntimeErrorrr�Futurer6r�r�r�rarwrr�r�r�)r
r8r9r:�f�wrrr�submit�s"

zProcessPoolExecutor.submitr&)�timeoutrWcs:|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.rW)r�)r�rE�maprr_r[r�)r
r8r�rWrX�resultsrGrrr��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)rxr�r�rwrr�r!r~rrr|)r
r�r�rrr�shutdown�s
(

zProcessPoolExecutor.shutdown)NNNr)T)rrrrr�r�r�r�r�r�ExecutorrQr�r�rRrrrGrr�?s�
U

r�)NN)1rQ�
__author__rk�concurrent.futuresrr��multiprocessingr�multiprocessing.connection�multiprocessing.queuesrr�ry�	functoolsrrUr�r.�WeakKeyDictionaryrrrr%�_register_atexitr�r��	Exceptionr(r,r3�objectr6r<r@rAr[r_rdrr�Threadrsr�r�r�r��BrokenExecutorr�r�r�rrrr�<module>sP*



)

Zerion Mini Shell 1.0