Hacked By AnonymousFox

Current Path : /opt/alt/python37/lib64/python3.7/concurrent/futures/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/concurrent/futures/__pycache__/process.cpython-37.opt-1.pyc

B

� ftm�@s�dZdZddlZddlZddlmZddlZddlmZddlZ	ddl
mZddlm
Z
ddlZddlZddlmZddlZddlZddlZe��Zd	aGd
d�d�Zdd
�ZdZdZGdd�de�ZGdd�d�Zdd�ZGdd�de �Z!Gdd�de �Z"Gdd�de �Z#Gdd�de
�Z$dd�Z%d d!�Z&d2d"d#�Z'd$d%�Z(d&d'�Z)d(d)�Z*d	a+da,d*d+�Z-d,d-�Z.Gd.d/�d/ej/�Z0Gd0d1�d1ej1�Z2e�3e�dS)3a*	Implements ProcessPoolExecutor.

The follow 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)�Full)�wait)�Queue)�partialFc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
_ThreadWakeupcCstjdd�\|_|_dS)NF)Zduplex)�mpZPipe�_reader�_writer)�self�r�?/opt/alt/python37/lib64/python3.7/concurrent/futures/process.py�__init__Rsz_ThreadWakeup.__init__cCs|j��|j��dS)N)r
�closer	)rrrr
rUs
z_ThreadWakeup.closecCs|j�d�dS)N�)r
Z
send_bytes)rrrr
�wakeupYsz_ThreadWakeup.wakeupcCsx|j��r|j��qWdS)N)r	ZpollZ
recv_bytes)rrrr
�clear\sz_ThreadWakeup.clearN)�__name__�
__module__�__qualname__rrrrrrrr
rQsrcCsHdatt���}x|D]\}}|��qWx|D]\}}|��q0WdS)NT)�_global_shutdown�list�_threads_wakeups�itemsr�join)r�_�
thread_wakeup�trrr
�_python_exitasr��=c@seZdZdd�Zdd�ZdS)�_RemoteTracebackcCs
||_dS)N)�tb)rr"rrr
rzsz_RemoteTraceback.__init__cCs|jS)N)r")rrrr
�__str__|sz_RemoteTraceback.__str__N)rrrrr#rrrr
r!ysr!c@seZdZdd�Zdd�ZdS)�_ExceptionWithTracebackcCs0t�t|�||�}d�|�}||_d||_dS)N�z

"""
%s""")�	traceback�format_exception�typer�excr")rr)r"rrr
r�s
z _ExceptionWithTraceback.__init__cCst|j|jffS)N)�_rebuild_excr)r")rrrr
�
__reduce__�sz"_ExceptionWithTraceback.__reduce__N)rrrrr+rrrr
r$sr$cCst|�|_|S)N)r!�	__cause__)r)r"rrr
r*�s
r*c@seZdZdd�ZdS)�	_WorkItemcCs||_||_||_||_dS)N)�future�fn�args�kwargs)rr.r/r0r1rrr
r�sz_WorkItem.__init__N)rrrrrrrr
r-�sr-c@seZdZddd�ZdS)�_ResultItemNcCs||_||_||_dS)N)�work_id�	exception�result)rr3r4r5rrr
r�sz_ResultItem.__init__)NN)rrrrrrrr
r2�sr2c@seZdZdd�ZdS)�	_CallItemcCs||_||_||_||_dS)N)r3r/r0r1)rr3r/r0r1rrr
r�sz_CallItem.__init__N)rrrrrrrr
r6�sr6cs.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�superr)r�max_sizer8r9)�	__class__rr
r�sz_SafeQueue.__init__cslt|t�rZt�t|�||j�}td�d�|���|_	|j
�|jd�}|dk	rh|j
�|�nt��||�dS)Nz

"""
{}"""r%)�
isinstancer6r&r'r(�
__traceback__r!�formatrr,r9�popr3r.�
set_exceptionr:�_on_queue_feeder_error)r�e�objr"�	work_item)r<rr
rB�s
z!_SafeQueue._on_queue_feeder_error)r)rrr�__doc__rrB�
__classcell__rr)r<r
r7�sr7cgs0t|�}x"tt�||��}|s"dS|Vq
WdS)z, Iterates over zip()ed iterables in chunks. N)�zip�tuple�	itertools�islice)�	chunksize�	iterables�it�chunkrrr
�_get_chunks�srPcs�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)�.0r0)r/rr
�
<listcomp>�sz"_process_chunk.<locals>.<listcomp>r)r/rOr)r/r
�_process_chunk�s	rSc
Cs^y|�t|||d��Wn@tk
rX}z"t||j�}|�t||d��Wdd}~XYnXdS)z.Safely send back the given result or exception)r5r4)r4N)�putr2�
BaseExceptionr$r>)�result_queuer3r5r4rCr)rrr
�_sendback_result�s
rWc
Cs�|dk	r:y||�Wn$tk
r8tjjddd�dSXx�|jdd�}|dkrb|�t���dSy|j|j	|j
�}Wn>tk
r�}z t||j�}t
||j|d�Wdd}~XYnXt
||j|d�~q<WdS)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)�block)r4)r5)rUrZLOGGERZcritical�getrT�os�getpidr/r0r1r$r>rWr3)�
call_queuerV�initializer�initargsZ	call_item�rrCr)rrr
�_process_worker�s$
"racCsxxr|��rdSy|jdd�}Wntjk
r4dSX||}|j��rh|jt||j|j	|j
�dd�q||=qqWdS)aMFills call_queue with _WorkItems from pending_work_items.

    This function never blocks.

    Args:
        pending_work_items: A dict mapping work ids to _WorkItems e.g.
            {5: <_WorkItem...>, 6: <_WorkItem...>, ...}
        work_ids: A queue.Queue of work ids e.g. Queue([5, 6, ...]). Work ids
            are consumed and the corresponding _WorkItems from
            pending_work_items are transformed into _CallItems and put in
            call_queue.
        call_queue: A multiprocessing.Queue that will be filled with _CallItems
            derived from _WorkItems.
    NF)rYT)ZfullrZ�queueZEmptyr.Zset_running_or_notify_cancelrTr6r/r0r1)r9Zwork_idsr]r3rErrr
�_add_call_item_to_queue�s 

rcc
sFd��fdd�}��fdd�}|j}	|j}
|	|
g}�xt||��dd����D�}t||�}
d}d}|	|
kr�y|	��}d	}Wq�tk
r�}zt�t|�||j	�}Wdd}~XYq�Xn|
|
kr�d	}d}|�
�|�rt|���dk	r�d
�_d�_d�t
d�}|dk	�r tdd
�|��d��|_x$|��D]\}}|j�|�~�q*W|�
�x���D]}|���qXW|�dSt|t��r���|�}|����s�|�dSnL|dk	�r�|�|jd�}|dk	�r�|j�r�|j�|j�n|j�|j�~~|��|��r:y$�dk	�rd�_|�s |�dSWntk
�r8YnXd�q6WdS)a,Manages the communication between this process and the worker processes.

    This function is run in a local thread.

    Args:
        executor_reference: A weakref.ref to the ProcessPoolExecutor that owns
            this thread. Used to determine if the ProcessPoolExecutor has been
            garbage collected and that this function can exit.
        process: A list of the ctx.Process instances used as
            workers.
        pending_work_items: A dict mapping work ids to _WorkItems e.g.
            {5: <_WorkItem...>, 6: <_WorkItem...>, ...}
        work_ids_queue: A queue.Queue of work ids e.g. Queue([5, 6, ...]).
        call_queue: A ctx.Queue that will be filled with _CallItems
            derived from _WorkItems for processing by the process workers.
        result_queue: A ctx.SimpleQueue of _ResultItems generated by the
            process workers.
        thread_wakeup: A _ThreadWakeup to allow waking up the
            queue_manager_thread from the main Thread and avoid deadlocks
            caused by permanently locked queues.
    Ncstp�dkp�jS)N)r�_shutdown_threadr)�executorrr
�
shutting_down?sz/_queue_management_worker.<locals>.shutting_downc	s�tdd����D��}|}d}xn||kr�|dkr�xBt||�D]2}y��d�|d7}Wq>tk
rnPYq>Xq>Wtdd����D��}q W���x���D]}|��q�WdS)Ncss|]}|��VqdS)N)�is_alive)rQ�prrr
�	<genexpr>EszD_queue_management_worker.<locals>.shutdown_worker.<locals>.<genexpr>rrcss|]}|��VqdS)N)rg)rQrhrrr
riQs)�sum�values�rangeZ
put_nowaitrrr)Zn_children_aliveZn_children_to_stopZn_sentinels_sent�irh)r]�	processesrr
�shutdown_workerCs
z1_queue_management_worker.<locals>.shutdown_workercSsg|]
}|j�qSr)�sentinel)rQrhrrr
rRhsz,_queue_management_worker.<locals>.<listcomp>TFzKA child process terminated abruptly, the process pool is not usable anymorez^A process in the process pool was terminated abruptly while the future was running or pending.z
'''
r%z''')r	rcrkrZrecvrUr&r'r(r>r�_brokenrd�BrokenProcessPoolr!rr,rr.rAZ	terminater=�intr@r3r4Z
set_resultr5r)Zexecutor_referencernr9Zwork_ids_queuer]rVrrfroZ
result_readerZ
wakeup_readerZreadersZworker_sentinelsZready�causeZ	is_brokenZresult_itemrCZbper3rErhr)r]rernr
�_queue_management_worker!s�(




ruc	Cshtrtrtt��dayt�d�}Wnttfk
r:dSX|dkrHdS|dkrTdSd|att��dS)NT�SC_SEM_NSEMS_MAX����z@system provides too few semaphores (%d available, 256 necessary))�_system_limits_checked�_system_limited�NotImplementedErrorr[�sysconf�AttributeError�
ValueError)Z	nsems_maxrrr
�_check_system_limits�srccs.x(|D] }|��x|r$|��VqWqWdS)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)�reverser@)�iterableZelementrrr
�_chain_from_iterable_of_lists�s
r�c@seZdZdZdS)rrzy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)rrrrFrrrr
rr�srrcsheZdZddd�Zdd�Zdd�Zd	d
�Zejjj	e_	ddd��fd
d�
Z
ddd�Zejjj	e_	�ZS)�ProcessPoolExecutorNrcCst�|dkr6t��pd|_tjdkrntt|j�|_n8|dkrHtd��n tjdkrh|tkrhtdt����||_|dkr~t	�
�}||_|dk	r�t|�s�t
d��||_||_d|_i|_d|_t��|_d|_d|_i|_|jt}t||j|jd	�|_d
|j_|��|_t� �|_!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.
        NrZwin32rz"max_workers must be greater than 0zmax_workers must be <= zinitializer must be a callableF)r;r8r9T)$rr[�	cpu_count�_max_workers�sys�platform�min�_MAX_WINDOWS_WORKERSr~rZget_context�_mp_context�callable�	TypeError�_initializer�	_initargs�_queue_management_thread�
_processesrd�	threadingZLock�_shutdown_lockrq�_queue_count�_pending_work_items�EXTRA_QUEUED_CALLSr7�_call_queueZ
_ignore_epipeZSimpleQueue�
_result_queuerbr�	_work_idsr�_queue_management_thread_wakeup)rZmax_workersZ
mp_contextr^r_Z
queue_sizerrr
r�sF







zProcessPoolExecutor.__init__c	Csv|jdkrr|jfdd�}|��tjtt�||�|j|j	|j
|j|j|jfdd�|_d|j_
|j��|jt|j<dS)NcSstj�d�|��dS)Nz?Executor collected: triggering callback for QueueManager wakeup)r�util�debugr)rrrrr
�
weakref_cbAszFProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cbZQueueManagerThread)�targetr0�nameT)r�r��_adjust_process_countr�ZThreadru�weakref�refr�r�r�r�r�Zdaemon�startr)rr�rrr
�_start_queue_management_thread<s 



z2ProcessPoolExecutor._start_queue_management_threadcCsTxNtt|j�|j�D]8}|jjt|j|j|j	|j
fd�}|��||j|j<qWdS)N)r�r0)
rl�lenr�r�r�ZProcessrar�r�r�r�r��pid)rrrhrrr
r�Wsz)ProcessPoolExecutor._adjust_process_countc	Os�t|�dkr|^}}}n>|s&td��n0d|krB|�d�}|^}}ntdt|�d��|j��|jrnt|j��|jr|td��tr�td��t	�
�}t||||�}||j|j
<|j�|j
�|j
d7_
|j��|��|SQRXdS)N�zEdescriptor 'submit' of 'ProcessPoolExecutor' object needs an argumentr/z6submit expected at least 1 positional argument, got %drz*cannot schedule new futures after shutdownz6cannot schedule new futures after interpreter shutdown)r�r�r@r�rqrrrd�RuntimeErrorrrZFuturer-r�r�r�rTr�rr�)r0r1rr/�f�wrrr
�submitbs0




zProcessPoolExecutor.submitr)�timeoutrLcs:|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.
        rzchunksize must be >= 1.rL)r�)r~r:�maprrSrPr�)rr/r�rLrMZresults)r<rr
r��szProcessPoolExecutor.mapTc	Cs�|j�d|_WdQRX|jr6|j��|r6|j��d|_|jdk	rd|j��|r^|j��d|_d|_	d|_
|jr�|j��d|_dS)NT)r�rdr�r�rrr�rZjoin_threadr�r�)rrrrr
�shutdown�s"





zProcessPoolExecutor.shutdown)NNNr)T)
rrrrr�r�r�r�ExecutorrFr�r�rGrr)r<r
r��s
J!
r�)NN)4rF�
__author__�atexitr[Zconcurrent.futuresrrbrZmultiprocessingrZmultiprocessing.connectionrZmultiprocessing.queuesrr�r��	functoolsrrJr�r&�WeakKeyDictionaryrrrrr�r��	Exceptionr!r$r*�objectr-r2r6r7rPrSrWrarcruryrzrr�ZBrokenExecutorrrr�r��registerrrrr
�<module>,sV
		

(&!L

Hacked By AnonymousFox1.0, Coded By AnonymousFox