σ
P'^c        
   @@  sσ   d  Z  d d l m Z d d l m Z y d d l m Z Wn e k
 rS d Z n Xd d l m	 Z	 d d l
 m Z m Z d g Z d i  d d d d d e e d	 	 Z d
 e	 j f d     YZ d e	 j f d     YZ d e f d     YZ d S(   s_   
    celery.concurrency.gevent
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    gevent pool implementation.

i    (   t   absolute_import(   t   time(   t   Timeout(   t   timer2i   (   t   apply_targett   BasePoolt   TaskPoolc
         K@  s^   y< | |  * |	 |  | | | | | d | f |
 SWd  QXWn | k
 rY | t  |  SXd  S(   Nt	   propagate(   t   False(   t   targett   argst   kwargst   callbackt   accept_callbackt   pidt   timeoutt   timeout_callbackR   R   t   rest(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   apply_timeout   s    	t   Schedulec           B@  s;   e  Z d    Z d   Z d   Z d   Z e d    Z RS(   c         @  sm   d d l  m   m } d   f   f d     Y} | |  _ | |  _ t t |   j | |   t   |  _	 d  S(   Ni    (   t   Greenlett   GreenletExitt	   _Greenletc           @  s   e  Z   j Z RS(    (   t   __name__t
   __module__t   killt   cancel(    (   R   (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR   +   s   (
   t   gevent.greenletR   R   R   t   _GreenletExitt   superR   t   __init__t   sett   _queue(   t   selfR
   R   R   R   (    (   R   s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR   (   s    		c         C@  ss   t  | t   d  } |  j j | |  } |  j j |  | j |  j  | | _ | | _	 | | _
 t | _ | S(   Ni    (   t   maxR   R   t   spawn_laterR    t   addt   linkt   _entry_exitt   entryt   etat   priorityR   t   canceled(   R!   R(   R)   R'   t   secst   g(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   _enter3   s    				c         C@  s&   z | j    Wd  |  j j |  Xd  S(   N(   R   R    t   discard(   R!   R,   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR&   >   s    c         C@  sB   |  j  } x2 | r= y | j   j   Wq t k
 r9 q Xq Wd  S(   N(   R    t   popR   t   KeyError(   R!   t   queue(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   clearD   s    		c         C@  s   |  j  S(   N(   R    (   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR1   L   s    (   R   R   R   R-   R&   R2   t   propertyR1   (    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR   &   s
   				t   Timerc           B@  s)   e  Z e Z d    Z d   Z d   Z RS(   c         C@  s   d  S(   N(    (   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   ensure_startedT   s    c         C@  s   |  j  j   d  S(   N(   t   scheduleR2   (   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   stopW   s    c         C@  s   d  S(   N(    (   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   startZ   s    (   R   R   R   R5   R7   R8   (    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR4   Q   s   		c           B@  s}   e  Z e Z e Z e Z e Z d    Z d   Z	 d   Z
 d d d d d d d  Z d d  Z d d  Z e d    Z RS(	   c         O@  sa   d d l  m } d d l m } | |  _ | |  _ | j d  |  _ t t |   j	 | |   d  S(   Ni    (   t	   spawn_raw(   t   PoolR   (
   t   geventR9   t   gevent.poolR:   t   spawn_nt   getR   R   R   R   (   R!   R
   R   R9   R:   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR   e   s    		c         C@  s(   |  j  |  j  |  _ |  j j |  _ d  S(   N(   R:   t   limitt   _poolt   spawnt
   _quick_put(   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   on_startm   s    c         C@  s#   |  j  d  k	 r |  j  j   n  d  S(   N(   R@   t   Nonet   join(   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   on_stopq   s    c   	      K@  sO   | d  k r |  j n | } |  j | r- t n t | | | | | d | d | S(   NR   R   (   RD   R   RB   R   R   (	   R!   R	   R
   R   R   R   R   R   t   _(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   on_applyu   s
    i   c         C@  s+   |  j  j j | 7_ |  j  j | 7_ d  S(   N(   R@   t
   _semaphoret   countert   size(   R!   t   n(    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   grow~   s    c         C@  s+   |  j  j j | 8_ |  j  j | 8_ d  S(   N(   R@   RI   RJ   RK   (   R!   RL   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   shrink   s    c         C@  s   t  |  j  S(   N(   t   lenR@   (   R!   (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   num_processes   s    N(   R   R   R4   R   t   signal_safet   Truet   is_greent   task_join_will_blockR   RC   RF   RD   RH   RM   RN   R3   RP   (    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyR   ^   s   				N(    (   t   __doc__t
   __future__R    R   R;   R   t   ImportErrorRD   t   celery.utilsR   t   baseR   R   t   __all__R   R   R4   R   (    (    (    s;   /tmp/pip-unpacked-wheel-gV1wwp/celery/concurrency/gevent.pyt   <module>   s    
			
+