ó
ÐH/\c           @   s'  d  Z  d d l Z e j d d g k rx d d l Z d „  Z y e j e ƒ j ƒ  Wn e k
 rg n Xe j d ƒ n« d d l	 Z	 d d l
 m Z m Z d d l Z d d l Z d d l j Z d d l m Z d d	 l m Z d d
 l m Z d e j f d „  ƒ  YZ e d k r#e j ƒ  n  d S(   s  Test for GitHub issues 461 and 471.

When moving to Python 3, handling of KeyboardInterrupt exceptions caused
by a Ctrl-C raised an exception while printing the traceback for a
greenlet preventing the process from exiting. This test tests for proper
handling of KeyboardInterrupt.
iÿÿÿÿNi   t
   subprocessc           C   s.   t  j j d ƒ t  j j ƒ  t j d ƒ d  S(   Ns   ready
i   (   t   syst   stdoutt   writet   flusht   geventt   sleep(    (    (    s?   lib/python2.7/site-packages/gevent/tests/test__issues461_471.pyt   task   s    i    (   t   Popent   PIPE(   t   CFFI_BACKEND(   t   RUN_COVERAGE(   t   WINt   Testc           B   s)   e  Z e j e o e d  ƒ d „  ƒ Z RS(   s   Interferes with the timingc   
      C   s¬  t  r& d d l m } i | d 6} n i  } t t j t d g d t | } | j j	 ƒ  } t
 | t ƒ s} | j d ƒ } n  | j ƒ  } |  j | d ƒ t  s¨ t j n t t d ƒ } | j | ƒ d	 } t j ƒ  } | | d
 } t j ƒ  | }	 x… t j ƒ  |	 k  r[| j ƒ  d  k	 rPn  t j ƒ  | k rK| j | ƒ |	 d } n  t j d ƒ q÷ W| j ƒ  | j ƒ  t d ƒ ‚ |  j t  s‘| j n d d ƒ | j j ƒ  d  S(   Niÿÿÿÿ(   t   CREATE_NEW_PROCESS_GROUPt   creationflagsR    R   t   asciit   readyt   CTRL_BREAK_EVENTg      .@g       @i   gš™™™™™¹?s   Failed to wait for childi    (   R   R    R   R   R   t
   executablet   __file__R	   R   t   readlinet
   isinstancet   strt   decodet   stript   assertEqualt   signalt   SIGINTt   getattrt   send_signalt   timet   pollt   NoneR   t	   terminatet   waitt   AssertionErrort
   returncodet   close(
   t   selfR   t   kwargst   pt   linet   signal_to_sendt   wait_secondst   nowt   midtimet   endtime(    (    s?   lib/python2.7/site-packages/gevent/tests/test__issues461_471.pyt	   test_hang'   s8    !

(   t   __name__t
   __module__t   unittestt   skipIfR
   R   R0   (    (    (    s?   lib/python2.7/site-packages/gevent/tests/test__issues461_471.pyR   %   s   t   __main__(   t   __doc__R   t   argvR   R   t   spawnt   gett   KeyboardInterruptt   exitR   R    R   R	   R   R3   t   gevent.testingt   testingt	   greentestt   gevent.testing.sysinfoR
   R   R   t   TestCaseR   R1   t   main(    (    (    s?   lib/python2.7/site-packages/gevent/tests/test__issues461_471.pyt   <module>   s(   	5