ó
å™xTc           @   sÌ   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	 Z	 d „  Z
 d e f d	 „  ƒ  YZ d
 e d e e d „ Z d „  Z d „  Z e d k rÈ e d e	 j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   unpicklable(   t   Exception_expected(   t   Auto(   t   StringIONc          C   sû   d d l  m }  |  d ƒ } | j d k s1 t ‚ |  d ƒ } | j d k sR t ‚ |  d ƒ } | j d k ss t ‚ |  d ƒ } | j d	 k s” t ‚ |  d
 ƒ } | j d k sµ t ‚ |  d ƒ } | j d k sÖ t ‚ |  d ƒ } | j d k s÷ t ‚ d  S(   Niÿÿÿÿ(   t   func_wrapper_sub_directoriest    s   %03dt   xs   x%03ds   %05dt   #s   %01ds   ##s   %02ds   y####s   y%04ds   #z###s	   #z###%03d(   t   libtbx.easy_mpR   t   sub_name_formatt   AssertionError(   t   ft   w(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt%   exercise_func_wrapper_sub_directories   s    t   potentially_largec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  d | d ƒ |  _ d  S(   Ni   (   t   ranget   array(   t   selft   size(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   __init__   s    c         C   s   |  j  | S(   N(   R   (   R   t   i(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   __call__   s    (   t   __name__t
   __module__R   R   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyR      s   	t   simplec   
      C   s`  t  |  j ƒ } t | ƒ } | r1 | j | ƒ n  d d l m } | rb | j d |  d | ƒ }	 nE | d k r} | r} d } n  | j d |  d | d | d	 | d
 | ƒ }	 | sÏ |	 t d | d ƒ k s\t ‚ n� |	 |  t d g | t d | d ƒ ƒ k st ‚ |	 | d j	 d ƒ st ‚ |	 | d j
 d ƒ d k sBt ‚ |	 | d d  k s\t ‚ d  S(   Niÿÿÿÿ(   t   easy_mpt   funct   argsR   t   buffer_stdout_stderrt
   fixed_funct   func_wrappert
   index_argst   logi   R   i    s   CAUGHT EXCEPTION:s   IndexError: i   (   t   lenR   R   t   appendt   libtbxR   t   pool_mapR   t   zipt
   startswitht   findt   None(
   t   dataR   R    R!   t   exercise_out_of_ranget   exercise_failR   R   R   t
   mp_results(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   eval_parallel!   s*    			"3#c            s�  t  ƒ  d d l m ‰  ˆ  j ƒ  } | d  k	 r< d | GHd  St d d ƒ } t | ƒ t ˆ  j ƒ d k sp t	 ‚ t | d d  d t
 ƒt ˆ  j ƒ d	 k s¡ t	 ‚ t | d d  d t
 d
 t j ƒt ˆ  j ƒ d k sÛ t	 ‚ t ƒ  } t | d d  d t
 d
 | ƒt ˆ  j ƒ d k st	 ‚ | j ƒ  j ƒ  } t | ƒ d k sEt	 ‚ | d j d ƒ s^t	 ‚ | d	 j d ƒ swt	 ‚ t | d t ƒ|  r¦t | d t ƒt ‚ n  ˆ  j d | d t d ƒ d t ƒ } ~ t ˆ  j ƒ d k sèt	 ‚ d d l m } d d l m } d d  l } | j }	 d „  ‰ ‡  ‡ f d †  }
 | d d d g ƒ |
 ƒ  } | d6 d7 g k slt	 ‚ xB d	 d g D]4 } | t d | d	 ƒ j ƒ  j ƒ  ƒ d | k qyW|
 ƒ  } | d8 d9 g k sÒt	 ‚ | d d g ƒ |
 ƒ  } | d: d; g k st	 ‚ | d d d g ƒ ˆ  j d ˆ d ˆ  j d! d ƒ d d	 d g ƒ } | d< d= g k s^t	 ‚ | d d d g ƒ | d d$ d% g ƒ d& „  } ˆ  j d | d d' d d	 d g ƒ } | d> d? g k sÉt	 ‚ xH d	 d g D]: } t d* | d	 ƒ j ƒ  j ƒ  d d+ | k sÖt	 ‚ qÖWt ƒ  ‰ d, „  } ‡ f d- †  } ˆ  j d. | d d	 d d d/ d0 d1 d2 d3 g d4 | d d	 ƒ } ˆ j ƒ  d5 k s‰t	 ‚ d  S(@   Niÿÿÿÿ(   R   s   Skipping tst_easy_mp.py: %sR   iè  i    R   R    i   R!   i   i   s   multiprocessing pool size: s   wall clock time: R+   R,   R   R   t	   processes(   t2   remove_or_rename_files_and_directories_if_possible(   t   only_elementc         S   s   d G|  GHd |  S(   Ns   hello worldi
   (    (   t   arg(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyR   b   s    	c              s"   ˆ  j  d ˆ d d d d d g ƒ S(   NR   R   t   sub_directoriesR   i   i   (   R%   (    (   R   R   (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   goe   s    	t   pathst   mp000t   mp001i
   i   s
   mp%03d/logs   hello world %ds%   sub-directory exists already: "mp000"s%   sub-directory exists already: "mp001"t   makedirs_modes&   cannot chdir to sub-directory: "mp000"s&   cannot chdir to sub-directory: "mp001"t   bf000t   bf001c         S   s   t  t |  ƒ ƒ ‚ d  S(   N(   t   RuntimeErrort   str(   R2   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   bad_funcƒ   s    s   sub_directories:bfs   CAUGHT EXCEPTION: "bf000/log"s   CAUGHT EXCEPTION: "bf001/log"s
   bf%03d/logs   RuntimeError: %dc         S   s`   d d l  m } t |  ƒ } d } x7 t d d ƒ D]& } | | | ƒ | t | ƒ ƒ 7} q2 W| S(   Niÿÿÿÿ(   R!   i    i   iè  (   t   mathR!   t   floatR   (   R2   R!   R   t   yR   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   simple_func�   s    $c            s   ˆ  j  d |  ƒ d  S(   Ns   %.3f
(   t   write(   t   result(   t   out(    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   cb—   s    R   i   i   i   i   i   t   call_back_for_serial_runs>   0.000
122.891
194.777
245.782
285.344
317.668
344.998
368.673
(   Ni
   (   Ni   (   s%   sub-directory exists already: "mp000"N(   s%   sub-directory exists already: "mp001"N(   s%   sub-directory exists already: "mp000"N(   Ni   (   s&   cannot chdir to sub-directory: "mp000"N(   s&   cannot chdir to sub-directory: "mp001"N(   s   CAUGHT EXCEPTION: "bf000/log"N(   s   CAUGHT EXCEPTION: "bf001/log"N(   R   R$   R   t   detect_problemR)   R   R.   R"   t   fixed_func_registryR   t   Falset   syst   stdoutR   t   getvaluet
   splitlinesR'   t   TrueR   R%   R   R   t   libtbx.clear_pathsR0   R1   t   ost   patht   opent   readR   (   R,   t
   mp_problemR*   t   siot   linest   resultst   clearR1   RP   t   opR4   R   R=   RA   RE   RC   (    (   R   R   RD   s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   exercise@   sž    	
		$			#					!						c         C   s@   |  g  d g g k s t  ‚ t |  ƒ d k } t | ƒ d GHd  S(   Ns   --faili    t   OK(   R   R"   RZ   (   R   R,   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   run©   s    
t   __main__R   i   (   t
   __future__R    R$   R   t   libtbx.test_utilsR   R   t	   cStringIOR   RJ   R   R   RN   R)   RI   R.   RZ   R\   R   t   argv(    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/tst_easy_mp.pyt   <module>   s    	
	i	