ó
šxTc           @   s�   d  d l  Z  d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿNt   Queuec           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s   
    Process queue
    c         C   sR   d | k  s t  ‚ | |  _ | |  _ g  |  _ t ƒ  |  _ t ƒ  |  _ d |  _ d  S(   Ni    g{®Gáz„?(   t   AssertionErrort   proxyt   nproct   waitingt   sett   runningt   completet   interval(   t   selfR   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   __init__   s    			c         C   s'   |  j  j | | | f ƒ |  j ƒ  d  S(   N(   R   t   appendt   poll(   R	   t   ownert   calculationt   extra(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   submit   s    c         C   s   |  j  S(   N(   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   empty   s    c         C   s   |  j  t |  j ƒ k S(   N(   R   t   lenR   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   full   s    c         C   s.   x' |  j  s) |  j ƒ  t j |  j ƒ q Wd  S(   N(   R   R   t   timet   sleepR   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   wait#   s    
c         C   s.   x' |  j  r) |  j ƒ  t j |  j ƒ q Wd  S(   N(   R   R   R   R   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   join*   s    
c         C   s.  xƒ t  |  j ƒ D]r } y | j ƒ  Wn, t k
 rR } d d l m } | | ‚ n X| j ƒ  r |  j j | ƒ |  j j	 | ƒ q q Wx¡ t
 |  j ƒ |  j k  r)|  j r)|  j j d ƒ \ } } } y" |  j d | d | d | ƒ } Wn, t k
 r} d d l m } | | ‚ n X|  j j	 | ƒ q‰ Wd  S(   Niÿÿÿÿ(   t   Sorryi    R   R   R   (   t   listR   R   t   RuntimeErrort   libtbx.utilsR   t   finishedt   removeR   t   addR   R   R   t   popR   (   R	   t   jobt   eR   R   R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   1   s"    $"c         C   s   t  |  j ƒ S(   N(   R   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt	   completedN   s    c         C   s   |  j  j | ƒ d  S(   N(   R   R   (   R	   R    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   S   s    (   t   __name__t
   __module__t   __doc__R
   R   R   R   R   R   R   R"   R   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR       s   								t   Jobc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s!   
    Stores related job info
    c         C   s1   | |  _  | |  _ | |  _ |  j j ƒ  |  _ d  S(   N(   R   R   R   t   runt   result(   R	   R   R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR
   ]   s    			c         C   s   d  S(   N(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   e   s    c         C   s   t  S(   N(   t   True(   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   j   s    c         C   s   d |  j  S(   Ns   (main thread) %s(   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   __str__o   s    (   R#   R$   R%   R
   R   R   R*   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR&   X   s
   			t   MPJobc           B   sV   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z e	 d „  ƒ Z
 e	 d „  ƒ Z RS(   s6   
    A job being run on a multiprocessing process
    c         C   s“   | |  _  | |  _ | |  _ d  |  _ |  j ƒ  s= |  j ƒ  n  d d  l } |  j j	 ƒ  |  _
 | j d t d |  j |  j
 f ƒ |  _ |  j j ƒ  d  S(   Niÿÿÿÿt   targett   args(   R   R   R   t   NoneR(   t   is_initializedt
   initializet   multiprocessingt   MANAGERR    t   queuet   Processt	   mpjob_runt   processt   start(   R	   R   R   R   R1   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR
   {   s    					c         C   sH   |  j  rD |  j  j ƒ  rD |  j j ƒ  |  _ |  j  j ƒ  d  |  _  n  d  S(   N(   R6   t   is_aliveR3   t   getR(   R   R.   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   Ž   s    c         C   s   |  j  d  k S(   N(   R6   R.   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   –   s    c         C   s   d |  j  S(   Ns   (multiprocessing) %s(   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR*   ›   s    c         C   s   d d  l  } | j ƒ  |  _ d  S(   Niÿÿÿÿ(   R1   t   ManagerR2   (   t   clsR1   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR0       s    c         C   s   |  j  d  k	 S(   N(   R2   R.   (   R;   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR/   §   s    N(   R#   R$   R%   R.   R2   R
   R   R   R*   t   classmethodR0   R/   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR+   t   s   				c         C   s   |  j  ƒ  } | j | ƒ d  S(   N(   R'   t   put(   R   R3   R(   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR5   ­   s    t   TJobc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s/   
    A job being run on a threading thread
    c         C   st   | |  _  | |  _ | |  _ d  |  _ d d  l } d d  l } | j ƒ  |  _ | j d |  j	 ƒ |  _
 |  j
 j ƒ  d  S(   NiÿÿÿÿR,   (   R   R   R   R.   R(   t	   threadingR    R3   t   ThreadR'   t   threadR7   (   R	   R   R   R   R?   R    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR
   ¸   s    				c         C   s#   |  j  j ƒ  } |  j j | ƒ d  S(   N(   R   R'   R3   R=   (   R	   R(   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR'   Æ   s    c         C   sQ   |  j  rM |  j  j ƒ  rM |  j j ƒ  |  _ |  j  j ƒ  d  |  _  d  |  _ n  d  S(   N(   RA   R8   R3   R9   R(   R   R.   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   Ì   s
    	c         C   s   |  j  d  k S(   N(   RA   R.   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR   Õ   s    c         C   s   d |  j  S(   Ns   (threading) %s(   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR*   Ú   s    (   R#   R$   R%   R
   R'   R   R   R*   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR>   ³   s   					t   QueueTargetc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
    An executable class
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R3   t   cpus(   R	   R   R3   RC   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR
   ä   s    		c         C   s,   |  j  j d |  j ƒ } |  j j | ƒ d  S(   NRC   (   R   R'   RC   R3   R=   (   R	   R(   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   __call__ë   s    (   R#   R$   R%   R
   RD   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyRB   ß   s   	t   QueueJobc           B   sG   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z	 RS(   s2   
    A job being run through a queuing system
    i<   c         C   sG   | |  _  | |  _ | |  _ d  |  _ | |  _ | |  _ |  j j ƒ  d  S(   N(   R   R   R   R.   R(   R3   R    R7   (   R	   R   R   R   R3   R    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR
   ø   s    						c         C   s¦   d d l  m } |  j r¢ |  j j ƒ  r¢ y% |  j j d t d |  j ƒ |  _ Wn/ | j	 k
 r } t
 d |  j j | f ‚ n X|  j j ƒ  d  |  _ d  |  _ n  d  S(   Niÿÿÿÿ(   t   generict   blockt   timeouts
   Job %s: %s(   t   libtbx.queuing_system_utilsRF   R    R8   R3   R9   R)   t   TIMEOUTR(   t   QueueEmptyExceptionR   t   nameR   R.   (   R	   RF   R!   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR     s    %	c         C   s   |  j  d  k S(   N(   R    R.   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR     s    c         C   s   d |  j  S(   Ns
   (queue) %s(   R   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyR*     s    c   
      C   sw   d d l  m } | j d d ƒ } | d d d t d | d | d	 | ƒ d
 | ƒ }	 |  d | d | d | d | d |	 ƒ S(   Niÿÿÿÿ(   RF   t
   identifiert   brtRL   R,   R   R3   RC   t
   qinterfaceR   R   R    (   RI   RF   R    RB   (
   R;   R   R   R   RO   t   factoryt
   qslot_cpusRF   R3   R    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   Generic  s    		(
   R#   R$   R%   RJ   R
   R   R   R*   R<   RR   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyRE   ñ   s   				(	   R   t   objectR    R&   R+   R5   R>   RB   RE   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/engine.pyt   <module>   s   U9	,