ó
úR‹_c           @   sf  d  d l  Z  d  d l 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 l m Z d  d	 l m Z e e d
 ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e e j f d „  ƒ  YZ d e e j f d „  ƒ  YZ d e f d „  ƒ  YZ e d ƒ d e e j f d „  ƒ  Yƒ Z e d k rbe j ƒ  n  d S(   iÿÿÿÿN(   t   gettrace(   t   settrace(   t   get_original(   t   thread_mod_name(   t   NativeStrIO(   t   skipOnPyPyOnWindows(   t   _monitor(   t   configt	   get_identt   MockHubc           B   sM   e  Z d Z d Z d  „  Z d „  Z e Z d „  Z e	 d „  ƒ Z
 d „  Z RS(   c         C   s%   t  ƒ  |  _ t ƒ  |  _ t |  _ d  S(   N(   R   t   thread_identR   t   exception_streamt   Falset   dead(   t   self(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   __init__   s    c         C   s   |  j  S(   N(   R   (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   __bool__   s    c         G   s   ‚  d  S(   N(    (   R   t   args(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   handle_error#   s    c         C   s   |  S(   N(    (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   loop&   s    c         C   s   d S(   s   mock loop.reinitN(    (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   reinit*   t    N(   t   __name__t
   __module__t   Nonet   _threadpoolt	   _resolverR   R   t   __nonzero__R   t   propertyR   R   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR	      s   			t%   _AbstractTestPeriodicMonitoringThreadc           B   s   e  Z d  „  Z d „  Z RS(   c            s±   t  t ˆ  ƒ j ƒ  t j ˆ  _ t j ˆ  _ d „  t _ d ˆ  _ ‡  f d †  } | t _ t	 ƒ  ˆ  _
 t j ˆ  j
 ƒ ˆ  _ ˆ  j ˆ  j
 _ ˆ  j j ƒ  ˆ  _ t ˆ  j ƒ ˆ  _ d  S(   Nc         S   s
   t  j ƒ  S(   N(   t   gct   collect(   t   _s(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   <lambda>6   R   Iï¾­Þ    c            s   ˆ  j  } ˆ  j  d 7_  | S(   Ni   (   t   tid(   t   _ft   _at   r(   R   (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   start_new_thread8   s    	(   t   superR   t   setUpt   monitorR&   t   _orig_start_new_threadt   thread_sleept   _orig_thread_sleepR"   R	   t   hubt   PeriodicMonitoringThreadt   pmtt   periodic_monitoring_threadt   monitoring_functionst   pmt_default_funcst   lent   len_pmt_default_funcs(   R   R&   (    (   R   sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR(   2   s    		c         C   sy   |  j  t _ |  j t _ |  j j j } |  j j ƒ  t	 ƒ  | k sX t
 t	 ƒ  | f ƒ ‚ t d  ƒ t t |  ƒ j ƒ  d  S(   N(   R*   R)   R&   R,   R+   R/   t   _greenlet_tracert   previous_trace_functiont   killR    t   AssertionErrorR   R   R'   R   t   tearDown(   R   t   prev(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR9   D   s    $
(   R   R   R(   R9   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR   -   s   	t   TestPeriodicMonitoringThreadc           B   sn   e  Z d  „  Z e d ƒ d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   c         C   s3   |  j  d |  j j ƒ |  j  t ƒ  |  j j ƒ d  S(   NIï¾­Þ    (   t   assertEqualR/   t   monitor_thread_identR    R5   (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_constructorQ   s    s%   psutil doesn't install on PyPy on Winc         C   s9   |  j  j ƒ  } |  j | ƒ |  j | |  j  j ƒ  ƒ d  S(   N(   R/   t   _get_processt   assertIsNotNonet   assertIs(   R   t   proc(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_get_processU   s    c         C   sc   |  j  |  j |  j j ƒ |  ` t j ƒ  |  j |  j j ƒ |  j |  j j ƒ |  j t ƒ  ƒ d  S(   N(	   RA   R-   R/   R   R   t   assertIsNonet   assertFalset
   should_runR    (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_hub_wref[   s    
c         C   s/  |  j  t |  j j d  d ƒ |  j  t |  j j d „  d ƒ d „  } |  j j | d ƒ |  j |  j d t |  j j ƒ  ƒ ƒ |  j d |  j j ƒ  d j	 ƒ |  j j | d ƒ |  j |  j d t |  j j ƒ  ƒ ƒ |  j d |  j j ƒ  d j	 ƒ |  j j | d  ƒ |  j |  j t |  j j ƒ  ƒ ƒ d  S(   Ni   c           S   s   d  S(   N(   R   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR!   j   R   iÿÿÿÿc           S   s   d S(   s   Does nothingN(    (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   fl   R   i   (
   t   assertRaisest
   ValueErrorR/   t   add_monitoring_functionR   R<   R4   R3   R1   t   period(   R   RH   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_add_monitoring_functiong   s    	& & c         C   sÖ   |  j  |  j j ƒ  d j |  j j ƒ  ƒ d |  j _ |  j  |  j j |  j j ƒ  ƒ d |  j j ƒ  d _ d |  j _ |  j j ƒ  |  j  |  j j ƒ  d j |  j j ƒ  ƒ |  j  |  j j ƒ  d j |  j j ƒ d  S(   Ni    iÿÿÿÿ(   R<   R/   R1   RL   t   calculate_sleep_timet   _calculated_sleep_timet   inactive_sleep_time(   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_calculate_sleep_time}   s     	c            sC   ‡  f d †  } ˆ  j  j | d ƒ ˆ  j  ƒ  ˆ  j ˆ  j  j ƒ d  S(   Nc            s   d  }  d  ˆ  _ t j ƒ  d  S(   N(   R   R-   R   R   (   t   _hub(   R   (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRH   ™   s    	gš™™™™™¹?(   R/   RK   RE   RF   (   R   RH   (    (   R   sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_call_destroyed_hub–   s    
c         C   s=   d „  } |  j  j | d ƒ |  j  ƒ  |  j |  j  j ƒ d  S(   Nc         S   s   t  |  _ d  S(   N(   t   TrueR   (   R-   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRH   ¥   s    gš™™™™™¹?(   R/   RK   RE   RF   (   R   RH   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_call_dead_hub¢   s    	
c         C   s*   d „  } |  j  j | d ƒ |  j  ƒ  d  S(   Nc         S   s   t  ƒ  ‚ d  S(   N(   t
   SystemExit(   RR   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRH   ­   s    gš™™™™™¹?(   R/   RK   (   R   RH   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_call_SystemExit«   s    	c            s\   d t  f d „  ƒ  Y‰  ‡  f d †  } |  j j | d ƒ |  j ˆ  ƒ  |  j ƒ  Wd  QXd  S(   Nt   MyExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRX   ´   s   c            s   ˆ  ƒ  ‚ d  S(   N(    (   RR   (   RX   (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRH   ·   s    gš™™™™™¹?(   t	   ExceptionR/   RK   RI   (   R   RH   (    (   RX   sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_call_other_error³   s
    c         C   s{   d d  l  } d d l m } d |  j _ |  j j } | |  j ƒ |  j | j ƒ  |  j j ƒ |  j | d |  j j ƒ d  S(   Niÿÿÿÿ(   R   i   (	   t   ost
   gevent.hubR   R/   t   pidR=   R-   R<   t   getpid(   R   R[   R   t   old_tid(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_hub_reinit¾   s    (   R   R   R>   R   RC   RG   RM   RQ   RS   RU   RW   RZ   R`   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR;   N   s   									t   TestPeriodicMonitorBlockingc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c            s³   |  j  j ƒ  |  j t ƒ  ƒ g  ‰  ‡  f d †  } t | ƒ t j |  j ƒ |  _  |  j t ƒ  |  j  j	 ƒ |  j
 |  j  j	 j | ƒ |  j  j	 d d ƒ |  j d d f g ˆ  ƒ d  S(   Nc             s   ˆ  j  |  ƒ d  S(   N(   t   append(   R   (   t   called(    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRH   Ó   s    t   eventR   (   R   (   R   (   R/   R7   RD   R    R   R)   R.   R-   R<   R5   RA   R6   (   R   RH   (    (   Rc   sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_previous_traceÎ   s    
c         C   sþ   |  j  d |  j j j ƒ |  j j d d  ƒ |  j  d |  j j j ƒ |  j |  j j j ƒ t ƒ  } t ƒ  } |  j j d | | f ƒ |  j  d |  j j j ƒ |  j | |  j j j ƒ |  j j d d ƒ |  j  d |  j j j ƒ |  j |  j j j ƒ d  S(   Ni    t   unknowni   t   switchi   i   (    (	   R<   R/   R5   t   greenlet_switch_counterR   RD   t   active_greenlett   objectRA   (   R   t   origint   target(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test__greenlet_tracerà   s    		c         C   s  d d l  m } d d l  m } d d l m } g  } | j | j ƒ |  j |  j j |  j	 ƒ ƒ t
 ƒ  } t
 ƒ  } |  j j d | | f ƒ |  j |  j j |  j	 ƒ ƒ |  j | ƒ |  j |  j j |  j	 ƒ ƒ |  j | ƒ | | | d ƒ | 2|  j j ƒ  |  j |  j j |  j	 ƒ ƒ |  j | ƒ |  j j ƒ  |  j |  j j |  j	 ƒ ƒ d |  j	 _ |  j |  j j |  j	 ƒ ƒ d  S(   Niÿÿÿÿ(   t   subscribers(   t   IEventLoopBlocked(   t   verifyObjectRg   i    (   t   gevent.eventsRn   Ro   t   zope.interface.verifyRp   Rb   RE   R/   t   monitor_blockingR-   Rj   R5   t
   assertTruet    ignore_current_greenlet_blockingt!   monitor_current_greenlet_blockingR
   (   R   Rn   Ro   Rp   t   eventsRk   Rl   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_monitor_blockingó   s,    		(   R   R   Re   Rm   Rx   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRa   Ë   s   		t   MockProcessc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   rss(   R   Rz   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR     s    c         C   s   |  S(   N(    (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   memory_full_info   s    (   R   R   R   R{   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyRy     s   	s%   psutil doesn't install on PyPy on Wint   TestPeriodicMonitorMemoryc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   i    c            sA   t  t ˆ  ƒ j ƒ  t j ˆ  _ d  t _ ‡  f d †  ˆ  j _ d  S(   Nc              s   t  ˆ  j ƒ S(   N(   Ry   Rz   (    (   R   (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR!   /  R   (	   R'   R|   R(   t   GEVENT_CONFIGt   max_memory_usaget   _old_maxR   R/   R?   (   R   (    (   R   sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR(   *  s    	c         C   s#   |  j  t _ t t |  ƒ j ƒ  d  S(   N(   R   R}   R~   R'   R|   R9   (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR9   1  s    c         C   sM   |  j  |  j j ƒ  ƒ |  j j ƒ  |  j |  j d t |  j j ƒ  ƒ ƒ d  S(   Ni   (   Rt   R/   t   can_monitor_memory_usaget   install_monitor_memory_usageR<   R4   R3   R1   (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_can_monitor_and_install5  s    c         C   s   d d  l  } d „  |  j _ |  j |  j j ƒ  ƒ | j d t ƒ  } |  j j ƒ  Wd  QX|  j d t	 | ƒ ƒ |  j
 t j | d j ƒ d  S(   Niÿÿÿÿc           S   s   d  S(   N(   R   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR!   A  R   t   recordi   i    (   t   warningsR/   R?   RE   R€   t   catch_warningsRT   R   R<   R3   RA   R)   t   MonitorWarningt   category(   R   R„   t   ws(    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_cannot_monitor_and_install?  s    c         C   s    |  j  d |  j j d  ƒ ƒ d  S(   Niÿÿÿÿ(   R<   R/   t   monitor_memory_usageR   (   R   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_monitor_no_allowedK  s    c         C   s  d d l  m } d |  _ d t _ |  j j d  ƒ } |  j | | j	 ƒ |  j
 d | j ƒ |  j
 d | j ƒ |  j | j t ƒ |  j j d  ƒ } |  j | ƒ d |  _ |  j j d  ƒ } |  j | | j	 ƒ |  j
 d | j ƒ d |  _ |  j j d  ƒ } |  j | | j ƒ |  j
 d | j ƒ t | ƒ |  j j d  ƒ } |  j | ƒ d |  _ |  j j d  ƒ } |  j | | j	 ƒ |  j
 d | j ƒ d  S(   Niÿÿÿÿ(   Rw   i   i   i   (   t   geventRw   Rz   R}   R~   R/   RŠ   R   t   assertIsInstancet   MemoryUsageThresholdExceededR<   t	   mem_usaget   max_allowedt   memory_infoRy   RD   t   MemoryUsageUnderThresholdt   repr(   R   Rw   Rd   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_monitor_greaterN  s2    				
	c         C   s5   d |  _  d t _ |  j j d  ƒ } |  j | ƒ d  S(   Ni   i
   (   Rz   R}   R~   R/   RŠ   R   RD   (   R   Rd   (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   test_monitor_initial_belowy  s    		(
   R   R   Rz   R(   R9   R‚   R‰   R‹   R”   R•   (    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyR|   $  s   			
			+t   __main__(   R   t   unittestt   greenletR    R   t   gevent.monkeyR   t   gevent._compatR   R   t   gevent.testing.skippingR   RŒ   R   R)   R   R}   R   Rj   R	   R   t   TestCaseR;   Ra   Ry   R|   R   t   main(    (    (    sT   /var/www/syncserver/local/lib/python2.7/site-packages/gevent/tests/test___monitor.pyt   <module>   s,   !|O	[