σ
P'^c           @@  sh  d  Z  d d l m Z d d l Z d d l m Z d d l m Z m Z m	 Z
 d d l m Z d d l m Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d d g Z e d d d d d g  Z e d g  Z  e e!  Z" e" j# e" j$ Z# Z$ d   Z% d   Z& d e f d     YZ' d S(   sw   
    celery.concurrency.prefork
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    Pool implementation using :mod:`multiprocessing`.

i    (   t   absolute_importN(   t   forking_enable(   t   RUNt   CLOSEt   Pool(   t	   platforms(   t   signals(   t   set_default_appt   _set_task_join_will_block(   t   trace(   t   BasePool(   t   items(   t   noop(   t
   get_loggeri   (   t   AsynPoolt   TaskPoolt   process_initializert   process_destructort   SIGTERMt   SIGHUPt   SIGTTINt   SIGTTOUt   SIGUSR1t   SIGINTc         C@  sΕ  t  t  t j j t   t j j t   t j d d | |  j	 j
   |  j	 j   t j j d  pl d } | r d | j   k r t |  j _ n  |  j j t t j j d d  pΊ d  | t t j j d t   t t j j d   d | t j j d	  rt j |   n* |  j   t |   |  j   |  j t _ d d
 l m } x> t  |  j!  D]- \ } } | | | |  j	 | d |  | _" qcWd d l# m$ } | j%   t j& j' d d  d S(   s¦   Pool child process initializer.

    This will initialize a child pool process to ensure the correct
    app instance is used and things like
    logging works.

    t   celerydt   hostnamet   CELERY_LOG_FILEs   %it   CELERY_LOG_LEVELi    t   CELERY_LOG_REDIRECTt   CELERY_LOG_REDIRECT_LEVELt   FORKED_BY_MULTIPROCESSING(   t   build_tracert   app(   t   statet   senderN((   R   t   TrueR   R   t   resett   WORKER_SIGRESETt   ignoret   WORKER_SIGIGNOREt   set_mp_process_titlet   loadert   init_workert   init_worker_processt   ost   environt   gett   Nonet   lowert   Falset   logt   already_setupt   setupt   intt   boolt   strR	   t   setup_worker_optimizationst   set_currentR   t   finalizet   _taskst   celery.app.traceR   R   t   taskst	   __trace__t   celery.workerR!   t   reset_statet   worker_process_initt   send(   R    R   t   logfileR   t   namet   taskt   worker_state(    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyR   +   s6    
'



c         C@  s#   t  j j d d d |  d |  d S(   s_   Pool child process destructor

    Dispatch the :signal:`worker_process_shutdown` signal.

    R"   t   pidt   exitcodeN(   R   t   worker_process_shutdownRB   R/   (   RG   RH   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyR   W   s    c           B@  s}   e  Z d  Z e Z e Z e Z d
 Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d	    Z RS(   s$   Multiprocessing Pool implementation.c      
   C@  sΊ   t  |  j   |  j j d t  r+ |  j n |  j } | d |  j d t d t d t	 |  j  } |  _
 | j |  _ | j |  _ | j |  _ | j |  _ | j |  _ t | d d  |  _ d S(   sa   Run the task pool.

        Will pre-fork all workers so they're ready to accept tasks.

        t   threadst	   processest   initializert   on_process_exitt   synackt   flushN(   R   t   optionsR.   R#   t   BlockingPoolR   t   limitR   R   R1   t   _poolt   apply_asynct   on_applyt   maintain_poolt   terminate_jobt   growt   shrinkt   getattrR/   RO   (   t   selfR   t   P(    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   on_startj   s    	c         C@  s!   |  j  j   |  j  j t  d  S(   N(   RS   t   restartRT   R   (   R[   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyR^      s    c         C@  s   |  j  j   S(   N(   RS   t   did_start_ok(   R[   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyR_      s    c         C@  s/   y |  j  j } Wn t k
 r$ d  SX| |  S(   N(   RS   t   register_with_event_loopt   AttributeError(   R[   t   loopt   reg(    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyR`      s
    c         C@  sQ   |  j  d k	 rM |  j  j t t f k rM |  j  j   |  j  j   d |  _  n  d S(   s   Gracefully stop the pool.N(   RS   R/   t   _stateR   R   t   closet   join(   R[   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   on_stop   s    'c         C@  s,   |  j  d k	 r( |  j  j   d |  _  n  d S(   s   Force terminate the pool.N(   RS   R/   t	   terminate(   R[   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   on_terminate   s    c         C@  s5   |  j  d  k	 r1 |  j  j t k r1 |  j  j   n  d  S(   N(   RS   R/   Rd   R   Re   (   R[   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   on_close   s    !c         C@  sͺ   y |  j  j } Wn t k
 r, d   } n Xi |  j d 6g  |  j  j  D] } | j ^ qG d 6|  j  j pl d d 6|  j d 6|  j  j p d |  j  j p d f d 6|   d	 6S(
   Nc           S@  s   d S(   Ns   N/A(    (    (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   write_stats€   s    s   max-concurrencyRK   s   N/As   max-tasks-per-childs   put-guarded-by-semaphorei    t   timeoutst   writes(	   RS   t   human_write_statsRa   RR   RG   t   _maxtasksperchildt   putlockst   soft_timeoutt   timeout(   R[   Rk   t   p(    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt	   _get_info    s    
#
c         C@  s
   |  j  j S(   N(   RS   t
   _processes(   R[   (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   num_processes°   s    N(   t   __name__t
   __module__t   __doc__R   R   RQ   R#   t   uses_semaphoreR/   Rk   R]   R^   R_   R`   Rg   Ri   Rj   Rt   t   propertyRv   (    (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyR   b   s   								((   Ry   t
   __future__R    R,   t   billiardR   t   billiard.poolR   R   R   RQ   t   celeryR   R   t   celery._stateR   R   t
   celery.appR	   t   celery.concurrency.baseR
   t   celery.fiveR   t   celery.utils.functionalR   t   celery.utils.logR   t   asynpoolR   t   __all__t	   frozensetR%   R'   Rw   t   loggert   warningt   debugR   R   R   (    (    (    s<   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/prefork.pyt   <module>   s2   	,	