σ
O'^c           @@  sΗ  d  Z  d d l m Z d d l 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 d d d d d d g Z d g Z e g Z g  Z e   Z e j j d  Z d e f d     YZ d e f d     YZ d   Z d e f d     YZ e e d e   Z d e f d     YZ  e e  d e   Z! d   Z" d   Z# e e d  Z$ d    Z% y! d d! l& m' Z' e' e e%  Wn e( k
 rΒn Xd S("   s2   
kombu.pools
===========

Public resource pools.

i    (   t   absolute_importN(   t   chaini   (   t   Resource(   t   ranget   values(   t   Producer(   t   EqualityDict(   t   lazyt   ProducerPoolt	   PoolGroupt   register_groupt   connectionst	   producerst	   get_limitt	   set_limitt   resetiΘ   t   KOMBU_DISABLE_LIMIT_PROTECTIONc           B@  sV   e  Z e Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   c         O@  sD   | |  _  | j d d   p! |  j |  _ t t |   j | |   d  S(   NR   (   R   t   popt   NoneR   t   superR   t   __init__(   t   selfR   t   argst   kwargs(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR       s    	c         C@  s   |  j  j d t  S(   Nt   block(   R   t   acquiret   True(   R   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   _acquire_connection%   s    c         C@  sB   |  j    } y |  j |  SWn t k
 r= | j     n Xd  S(   N(   R   R   t   BaseExceptiont   release(   R   t   conn(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   create_producer(   s    
c         C@  s   t  |  j  S(   N(   R   R   (   R   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   new0   s    c         C@  s@   |  j  r< x0 t |  j   D] } |  j j |  j    q Wn  d  S(   N(   t   limitR   t	   _resourcet
   put_nowaitR    (   R   t   _(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   setup3   s    	c         C@  s   d  S(   N(    (   R   t   resource(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   close_resource8   s    c         C@  sl   t  |  r |   } n  | j d  k rh |  j   } y | j |  Wqh t k
 rd | j     qh Xn  | S(   N(   t   callablet   _channelR   R   t   reviveR   R   (   R   t   pR   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   prepare;   s    

c         C@  s<   | j  r | j  j   n  d  | _ t t |   j |  d  S(   N(   t   __connection__R   R   t   channelR   R   (   R   R&   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR   G   s    		(   t   __name__t
   __module__R   R   R   R   R    R%   R'   R,   R   (    (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR      s   							c           B@  s&   e  Z d d   Z d   Z d   Z RS(   c         C@  s   | |  _  d  S(   N(   R!   (   R   R!   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR   P   s    c         C@  s   t  d   d  S(   Ns!   PoolGroups must define ``create``(   t   NotImplementedError(   R   R&   R!   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   createS   s    c         C@  sV   |  j  } | t k r! t   } n  t d s8 t t d <n  |  j | |  } |  | <| S(   Ni    (   R!   t   use_global_limitR   t   _usedR   R2   (   R   R&   R!   t   k(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   __missing__V   s    	
N(   R/   R0   R   R   R2   R6   (    (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR	   N   s   	c         C@  s   t  j |   |  S(   N(   t   _groupst   append(   t   group(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR
   `   s    t   Connectionsc           B@  s   e  Z d    Z RS(   c         C@  s   | j  d |  S(   NR!   (   t   Pool(   R   t
   connectionR!   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR2   g   s    (   R/   R0   R2   (    (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR:   e   s   R!   t	   Producersc           B@  s   e  Z d    Z RS(   c         C@  s   t  t | d | S(   NR!   (   R   R   (   R   R<   R!   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR2   n   s    (   R/   R0   R2   (    (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR=   l   s   c          C@  s5   t  g  t D]$ }  |  r" t |   n	 t g   ^ q
   S(   N(   R   R7   R   t   iter(   t   g(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt
   _all_poolss   s    c           C@  s   t  d S(   Ni    (   t   _limit(    (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR   w   s    c         C@  s’   |  p	 d }  t  d p d } |  | k  rX t rO t d rO | rO t d   n  t } n  |  | k r |  t  d <x t   D] } |  | _ qx W| r t   q n  |  S(   Ni    s$   Can't lower limit after pool in use.(   RA   t   disable_limit_protectionR4   t   RuntimeErrorR   R@   R!   R   (   R!   t   forcet   reset_aftert   glimitt   pool(    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR   {   s    	
c          O@  s_   x3 t    D]( } y | j   Wq
 t k
 r1 q
 Xq
 Wx t D] } | j   q= Wt t d <d  S(   Ni    (   R@   t   force_close_allt	   ExceptionR7   t   cleart   FalseR4   (   R   R   RG   R9   (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyR      s    (   t   register_after_fork()   t   __doc__t
   __future__R    t   ost	   itertoolsR   R<   R   t   fiveR   R   t	   messagingR   t   utilsR   t   utils.functionalR   t   __all__RA   RK   R4   R7   t   objectR3   t   environt   getRB   R   R	   R
   R:   R   R=   R   R@   R   R   R   t   multiprocessing.utilRL   t   ImportError(    (    (    s-   /tmp/pip-unpacked-wheel-UAnTfW/kombu/pools.pyt   <module>   s>   				1				
