File "process.cpython-34.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python34/lib64/python3.4/concurrent/futures/__pycache__/process.cpython-34.pyc
File size: 12.71 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit


j fD@svdZdZddlZddlZddlmZddlZddlmZddlZddlm	Z	ddl
mZddlZddl
Z
e
jZdad	d
ZdZGdd
d
eZGdddeZGdddeZddZddZddZdadaddZGdddeZGdddejZ ej!edS)a*	Implements ProcessPoolExecutor.

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

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

+----------+     +----------+       +--------+     +-----------+    +---------+
|          |  => | Work Ids |    => |        |  => | Call Q    | => |         |
|          |     +----------+       |        |     +-----------+    |         |
|          |     | ...      |       |        |     | ...       |    |         |
|          |     | 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)SimpleQueue)waitFcCsadattj}x!|D]\}}|jdqWx|D]\}}|jqCWdS)NT)	_shutdownlist_threads_queuesitemsputjoin)r	tqr?/opt/alt/python34/lib64/python3.4/concurrent/futures/process.py_python_exitLsrc@seZdZddZdS)	_WorkItemcCs(||_||_||_||_dS)N)futurefnargskwargs)selfrrrrrrr__init__\s			z_WorkItem.__init__N)__name__
__module____qualname__rrrrrr[src@s"eZdZddddZdS)_ResultItemNcCs||_||_||_dS)N)work_id	exceptionresult)rrrrrrrrcs		z_ResultItem.__init__)rrrrrrrrrbsrc@seZdZddZdS)	_CallItemcCs(||_||_||_||_dS)N)rrrr)rrrrrrrrris			z_CallItem.__init__N)rrrrrrrrr hsr cCsx|jdd}|dkr8|jtjdSy|j|j|j}WnAtk
r}z!|jt|j	d|WYdd}~XqX|jt|j	d|qWdS)aEvaluates calls from call_queue and places the results in result_queue.

    This worker is run in a separate process.

    Args:
        call_queue: A multiprocessing.Queue of _CallItems that will be read and
            evaluated by the worker.
        result_queue: A multiprocessing.Queue of _ResultItems that will written
            to by the worker.
        shutdown: A multiprocessing.Event that will be set as a signal to the
            worker that it should exit when call_queue is empty.
    blockTNrr)
getr
osgetpidrrr
BaseExceptionrr)
call_queueresult_queueZ	call_itemrerrr_process_workeros
r*cCsx|jrdSy|jdd}Wntjk
rDdSYqX||}|jjr|jt||j|j	|j
ddq||=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.
    Nr!FT)fullr"queueZEmptyrZset_running_or_notify_cancelr
r rrr)pending_work_itemsZwork_idsr&r	work_itemrrr_add_call_item_to_queues 	

r/cs8dfdd}fdd}|j}xt||ddjD}	|	sntt|g|	}
||
kr|j}n|dk	rd_d_dnx3|jD]%\}}
|
j	j
td	~
qW|jxjD]}|j
qW|dSt|tr|sVtj|}|js|dSnh|dk	r|j|jd}
|
dk	r|jr|
j	j
|jn|
j	j|j~
qn||r*y|s|dSWq*tk
r&Yq*Xndq9WdS)
aManages 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 multiprocessing.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 multiprocessing.Queue that will be filled with _CallItems
            derived from _WorkItems for processing by the process workers.
        result_queue: A multiprocessing.Queue of _ResultItems generated by the
            process workers.
    NcstpdkpjS)N)r_shutdown_threadr)executorrr
shutting_downsz/_queue_management_worker.<locals>.shutting_downcsutddjD}x$td|D]}jdq/WjxjD]}|jq]WdS)Ncss|]}|jVqdS)N)Zis_alive).0prrr	<genexpr>szD_queue_management_worker.<locals>.shutdown_worker.<locals>.<genexpr>r)sumvaluesrangeZ
put_nowaitcloser)Znb_children_aliveir4)r&	processesrrshutdown_workers
z1_queue_management_worker.<locals>.shutdown_workercSsg|]}|jqSr)sentinel)r3r4rrr
<listcomp>s	z,_queue_management_worker.<locals>.<listcomp>Tz^A process in the process pool was terminated abruptly while the future was running or pending.)Z_readerr/r7AssertionErrorrZrecv_brokenr0r	rZ
set_exceptionBrokenProcessPoolclearZ	terminate
isinstanceintpoprrrZ
set_resultrr)Zexecutor_referencer;r-Zwork_ids_queuer&r'r2r<readerZ	sentinelsZreadyZresult_itemrr.r4r)r&r1r;r_queue_management_workersf						


				
rGcCstrtrttqndaytjd}Wnttfk
rUdSYnX|dkrfdS|dkrvdSd|attdS)NTSC_SEM_NSEMS_MAXrz@system provides too few semaphores (%d available, 256 necessary))_system_limits_checked_system_limitedNotImplementedErrorr#sysconfAttributeError
ValueError)Z	nsems_maxrrr_check_system_limits%s	
rQc@seZdZdZdS)rAzy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N)rrr__doc__rrrrrA<srAc@sveZdZdddZddZddZdd	Zejjj	e_	d
ddZ
ejj
j	e
_	dS)
ProcessPoolExecutorNcCst|dkr+tjp"d|_n	||_tj|jt|_d|j_t	|_
tj|_d|_
i|_d|_tj|_d|_d|_i|_dS)a/Initializes 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.
        NrTFr)rQr#	cpu_count_max_workersmultiprocessingZQueueEXTRA_QUEUED_CALLS_call_queueZ
_ignore_epiper
_result_queuer,	_work_ids_queue_management_thread
_processesr0	threadingZLock_shutdown_lockr@_queue_count_pending_work_items)rZmax_workersrrrrDs 	
					zProcessPoolExecutor.__init__c
Cs|jdd}|jdkr|jtjdtdtj|||j|j	|j
|j|jf|_d|j_|jj
|jt|j<ndS)NcSs|jddS)N)r
)_r
rrr
weakref_cblszFProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cbtargetrT)rYr[_adjust_process_countr]ZThreadrGweakrefrefr\r`rZrXZdaemonstartr)rrbrrr_start_queue_management_threadis
	
z2ProcessPoolExecutor._start_queue_management_threadcCshxatt|j|jD]D}tjdtd|j|jf}|j	||j|j
<qWdS)Nrcr)r8lenr\rUrVZProcessr*rXrYrgpid)rrar4rrrrd}s"	
z)ProcessPoolExecutor._adjust_process_countcOs|j|jr"tdn|jr:tdntj}t||||}||j|j	<|j
j|j	|j	d7_	|jjd|j
|SWdQXdS)NzKA child process terminated abruptly, the process pool is not usable anymorez*cannot schedule new futures after shutdownr)r^r@rAr0RuntimeErrorrZFuturerr`r_rZr
rYrh)rrrrfwrrrsubmits
		
zProcessPoolExecutor.submitTc	Css|jd|_WdQX|jrK|jjd|rK|jjqKnd|_d|_d|_d|_dS)NT)r^r0r[rYr
rrXr\)rrrrrshutdowns
				zProcessPoolExecutor.shutdown)rrrrrhrdrnrExecutorrRrorrrrrSCs%	rS)"rR
__author__atexitr#Zconcurrent.futuresrr,rrVrZmultiprocessing.connectionrr]reWeakKeyDictionaryrrrrWobjectrrr r*r/rGrKrLrQrkrArprSregisterrrrr<module>,s6
%sh