Hacked By AnonymousFox

Current Path : /opt/alt/python33/lib64/python3.3/concurrent/futures/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/concurrent/futures/__pycache__/process.cpython-33.pyo

�
��f�Cc@sldZdZddlZddlZddlmZddlZddlZddlm	Z	m
Z
ddlmZddl
Z
ddlZej�Zdadd�Zd	ZGd
d�de�ZGdd
�d
e�ZGdd�de�Zdd�Zdd�Zdd�Zdadadd�ZGdd�de �Z!Gdd�dej"�Z#ej$e�dS(u+	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 "Request Q"
u"Brian Quinlan (brian@sweetapp.com)iN(u_base(uSimpleQueueuFull(uwaitcCsadattj��}x!|D]\}}|jd�qWx|D]\}}|j�qCWdS(NT(uTrueu	_shutdownulistu_threads_queuesuitemsuputuNoneujoin(uitemsutuq((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_python_exitKsu_python_exiticBs |EeZdZdd�ZdS(u	_WorkItemcCs(||_||_||_||_dS(N(ufutureufnuargsukwargs(uselfufutureufnuargsukwargs((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu__init__[s			u_WorkItem.__init__N(u__name__u
__module__u__qualname__u__init__(u
__locals__((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu	_WorkItemZsu	_WorkItemcBs&|EeZdZdddd�ZdS(u_ResultItemcCs||_||_||_dS(N(uwork_idu	exceptionuresult(uselfuwork_idu	exceptionuresult((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu__init__bs		u_ResultItem.__init__N(u__name__u
__module__u__qualname__uNoneu__init__(u
__locals__((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_ResultItemasu_ResultItemcBs |EeZdZdd�ZdS(u	_CallItemcCs(||_||_||_||_dS(N(uwork_idufnuargsukwargs(uselfuwork_idufnuargsukwargs((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu__init__hs			u_CallItem.__init__N(u__name__u
__module__u__qualname__u__init__(u
__locals__((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu	_CallItemgsu	_CallItemcCs�x�|jdd�}|dkr8|jtj��dSy|j|j|j�}WnAt	k
r�}z!|jt
|jd|��WYdd}~XqX|jt
|jd|��qdS(u�Evaluates 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.
    ublockNu	exceptionuresultT(ugetuTrueuNoneuputuosugetpidufnuargsukwargsu
BaseExceptionu_ResultItemuwork_id(u
call_queueuresult_queueu	call_itemurue((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_process_workerns
u_process_workercCs�x�|j�rdSy|jdd�}Wntjk
rDdSYqX||}|jj�r�|jt||j	|j
|j�dd�q||=qqdS(uMFills 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.
    NublockFT(
ufullugetuFalseuqueueuEmptyufutureuset_running_or_notify_canceluputu	_CallItemufnuargsukwargsuTrue(upending_work_itemsuwork_idsu
call_queueuwork_idu	work_item((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_add_call_item_to_queue�s 	

u_add_call_item_to_queuecsd��fdd�}��fdd�}|j}x�t||��dd��j�D�}	t|g|	�}
||
kr�|j�}n�|���dk	r�d	�_d	�_d�nx0|j	�D]"\}}
|
j
jtd��q�W|j
�x�j�D]}|j�q
W|�dSt|t�re�j|�}|j��s�|�dSne|dk	r�|j|jd�}
|
dk	r�|jr�|
j
j|j�q�|
j
j|j�q�n|��|�r	y|s�|�dSWq	tk
rYq	Xnd�q9dS(
u�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 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.
    cstp�dkp�jS(N(u	_shutdownuNoneu_shutdown_thread((uexecutor(u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu
shutting_down�su/_queue_management_worker.<locals>.shutting_downcsutdd��j�D��}x$td|�D]}�jd�q/W�j�x�j�D]}|j�q]WdS(Ncss|]}|j�VqdS(N(uis_alive(u.0up((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu	<genexpr>�suD_queue_management_worker.<locals>.shutdown_worker.<locals>.<genexpr>i(usumuvaluesurangeu
put_nowaituNoneucloseujoin(unb_children_aliveuiup(u
call_queueu	processes(u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyushutdown_worker�s
u1_queue_management_worker.<locals>.shutdown_workercSsg|]}|j�qS((usentinel(u.0up((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu
<listcomp>�s	u,_queue_management_worker.<locals>.<listcomp>u^A process in the process pool was terminated abruptly while the future was running or pending.NT(uNoneu_readeru_add_call_item_to_queueuvaluesuwaiturecvuTrueu_brokenu_shutdown_threaduitemsufutureu
set_exceptionuBrokenProcessPooluclearu	terminateu
isinstanceuintupopujoinuwork_idu	exceptionu
set_resulturesultuFull(uexecutor_referenceu	processesupending_work_itemsuwork_ids_queueu
call_queueuresult_queueu
shutting_downushutdown_workerureaderu	sentinelsureadyuresult_itemuwork_idu	work_itemup((u
call_queueuexecutoru	processesu?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_queue_management_worker�s^						

			
u_queue_management_workercCs�trtrtt��qndaytjd�}Wnttfk
rUdSYnX|dkrfdS|dkrvdSd|att��dS(NuSC_SEM_NSEMS_MAXiiu@system provides too few semaphores (%d available, 256 necessary)Ti����(u_system_limits_checkedu_system_limiteduNotImplementedErroruTrueuosusysconfuAttributeErroru
ValueError(u	nsems_max((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_check_system_limits s	
u_check_system_limitscBs|EeZdZdZdS(uBrokenProcessPooluy
    Raised when a process in a ProcessPoolExecutor terminated abruptly
    while a future was in the running state.
    N(u__name__u
__module__u__qualname__u__doc__(u
__locals__((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyuBrokenProcessPool7suBrokenProcessPoolcBsz|EeZdZddd�Zdd�Zdd�Zdd�Zej	jj
e_
dd	d
�Zej	jj
e_
dS(
uProcessPoolExecutorcCs�t�|dkr%tj�|_n	||_tj|jt�|_d|j_	t
�|_tj�|_
d|_i|_d|_tj�|_d|_d|_i|_dS(u/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.
        iNTF(u_check_system_limitsuNoneumultiprocessingu	cpu_countu_max_workersuQueueuEXTRA_QUEUED_CALLSu_call_queueuTrueu
_ignore_epipeuSimpleQueueu
_result_queueuqueueu	_work_idsu_queue_management_threadu
_processesuFalseu_shutdown_threadu	threadinguLocku_shutdown_locku_brokenu_queue_countu_pending_work_items(uselfumax_workers((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu__init__?s 	
					uProcessPoolExecutor.__init__c
Cs�|jdd�}|jdkr�|j�tjdtdtj||�|j	|j
|j|j|jf�|_d|j_|jj�|jt|j<ndS(NcSs|jd�dS(N(uputuNone(u_uq((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu
weakref_cbgsuFProcessPoolExecutor._start_queue_management_thread.<locals>.weakref_cbutargetuargsT(u
_result_queueu_queue_management_threaduNoneu_adjust_process_countu	threadinguThreadu_queue_management_workeruweakrefurefu
_processesu_pending_work_itemsu	_work_idsu_call_queueuTrueudaemonustartu_threads_queues(uselfu
weakref_cb((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_start_queue_management_threadds
	
u2ProcessPoolExecutor._start_queue_management_threadcCshxatt|j�|j�D]D}tjdtd|j|jf�}|j	�||j|j
<qWdS(Nutargetuargs(urangeulenu
_processesu_max_workersumultiprocessinguProcessu_process_workeru_call_queueu
_result_queueustartupid(uselfu_up((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu_adjust_process_countxs"	
u)ProcessPoolExecutor._adjust_process_countcOs�|j��|jr"td��n|jr:td��ntj�}t||||�}||j|j	<|j
j|j	�|j	d7_	|jjd�|j�|SWdQXdS(NuKA child process terminated abruptly, the process pool is not usable anymoreu*cannot schedule new futures after shutdowni(u_shutdown_locku_brokenuBrokenProcessPoolu_shutdown_threaduRuntimeErroru_baseuFutureu	_WorkItemu_pending_work_itemsu_queue_countu	_work_idsuputu
_result_queueuNoneu_start_queue_management_thread(uselfufnuargsukwargsufuw((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyusubmit�s
		
uProcessPoolExecutor.submitc	Css|j�d|_WdQX|jrK|jjd�|rK|jj�qKnd|_d|_d|_d|_	dS(NT(
u_shutdown_lockuTrueu_shutdown_threadu_queue_management_threadu
_result_queueuputuNoneujoinu_call_queueu
_processes(uselfuwait((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyushutdown�s
				uProcessPoolExecutor.shutdownNT(
u__name__u
__module__u__qualname__uNoneu__init__u_start_queue_management_threadu_adjust_process_countusubmitu_baseuExecutoru__doc__uTrueushutdown(u
__locals__((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyuProcessPoolExecutor>s%	uProcessPoolExecutorF(%u__doc__u
__author__uatexituosuconcurrent.futuresu_baseuqueueumultiprocessingumultiprocessing.queuesuSimpleQueueuFullumultiprocessing.connectionuwaitu	threadinguweakrefuWeakKeyDictionaryu_threads_queuesuFalseu	_shutdownu_python_exituEXTRA_QUEUED_CALLSuobjectu	_WorkItemu_ResultItemu	_CallItemu_process_workeru_add_call_item_to_queueu_queue_management_workeru_system_limits_checkeduNoneu_system_limitedu_check_system_limitsuRuntimeErroruBrokenProcessPooluExecutoruProcessPoolExecutoruregister(((u?/opt/alt/python33/lib64/python3.3/concurrent/futures/process.pyu<module>,s4
%oh

Hacked By AnonymousFox1.0, Coded By AnonymousFox