ó
ÐH/\c           @  s   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l j Z	 d Z
 d e j f d „  ƒ  YZ e d k r‹ e	 j ƒ  n  d S(   iÿÿÿÿ(   t   print_functionN(   t   allocate_locks·  
from gevent import monkey
monkey.patch_all()
import sys, os, threading, time


# A deadlock-killer, to prevent the
# testsuite to hang forever
def killer():
    time.sleep(0.1)
    sys.stdout.write('..program blocked; aborting!')
    sys.stdout.flush()
    os._exit(2)
t = threading.Thread(target=killer)
t.daemon = True
t.start()


def trace(frame, event, arg):
    if threading is not None:
        threading.currentThread()
    return trace


def doit():
    sys.stdout.write("..thread started..")


def test1():
    t = threading.Thread(target=doit)
    t.start()
    t.join()
    sys.settrace(None)

sys.settrace(trace)
if len(sys.argv) > 1:
    test1()

sys.stdout.write("..finishing..")
t	   TestTracec           B  sn   e  Z e j d  ƒ d „  ƒ Z e j d  ƒ d „  ƒ Z e j d  ƒ d „  ƒ Z d d „ Z d „  Z d „  Z	 RS(   s"   Locks can be traced in Pure Pythonc           s…   t  t d ƒ r t j ƒ  } n d  } g  ‰  z3 ‡  ‡ f d †  ‰ t ƒ   t j ˆ ƒ Wd  QXWd  t j | ƒ X|  j ˆ  g  d ƒ d  S(   Nt   gettracec           s5   ˆ  j  |  j j |  j | f ƒ t d ˆ  d ƒ ˆ S(   Ns   TRACE: %s:%s %siÿÿÿÿ(   t   appendt   f_codet   co_filenamet   f_linenot   print(   t   framet   evt   _arg(   t   lstt   trace(    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyR   B   s    s   trace not empty(   t   hasattrt   sysR   t   NoneR   t   settracet   assertEqual(   t   selft   old(    (   R   R   sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt   test_untraceable_lock3   s    
c           sÊ   t  t d ƒ r t j ƒ  } n d  } t j d d k } g  ‰ t ƒ  ‰  zC ‡  ‡ ‡ f d †  ‰ t ƒ  } t j ˆ ƒ | j ƒ  | j ƒ  Wd  t j | ƒ X| s¶ |  j	 ˆ g  d ƒ n |  j
 ˆ d ƒ d  S(   NR   i    i   c           sB   ˆ  $ ˆ j  |  j j |  j | f ƒ Wd  QXt d ˆ d ƒ ˆ S(   Ns   TRACE: %s:%s %siÿÿÿÿ(   R   R   R   R   R   (   R	   R
   R   (   t   lR   R   (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyR   Z   s    %s   trace not emptys   should not compile on pypy(   R   R   R   R   t   version_infoR   R   t   acquiret   releaseR   t
   assertTrue(   R   R   t   PY3t   l2(    (   R   R   R   sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt)   test_untraceable_lock_uses_different_lockN   s     		
c           s  d d l  m } t t d ƒ r. t j ƒ  } n d  } t j d d k } g  ‰ d  } t ƒ  ‰  zP y0 ‡  ‡ ‡ f d †  ‰ t j ˆ ƒ ˆ  j	 ƒ  Wn | k
 rª } | } n XWd  t j | ƒ X| sÙ |  j
 ˆ g  d ƒ n& |  j ˆ d ƒ |  j t | | ƒ ƒ d  S(	   Niÿÿÿÿ(   t   LoopExitR   i    i   c           s0   ˆ  $ ˆ j  |  j j |  j | f ƒ Wd  QXˆ S(   N(   R   R   R   R   (   R	   R
   R   (   R   R   R   (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyR   ~   s    %s   trace not emptys   should not compile on pypy(   t
   gevent.hubR   R   R   R   R   R   R   R   R   R   R   t
   isinstance(   R   R   R   R   t   et   ex(    (   R   R   R   sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt$   test_untraceable_lock_uses_same_lockp   s(    	 c         C  sX   t  j d t g } | j | ƒ t j | ƒ } |  j | d d ƒ |  j | d d ƒ d  S(   Ns   -ci   s   interpreter was blockedi    s   Unexpected error(   R   t
   executablet   scriptt   extendt
   subprocesst   callt   assertNotEqualR   (   R   t	   more_argst   argst   rc(    (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt
   run_script”   s
    c         C  s   |  j  ƒ  d  S(   N(   R-   (   R   (    (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt   test_finalize_with_trace›   s    c         C  s   |  j  d g ƒ d  S(   Nt   1(   R-   (   R   (    (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt   test_bootstrap_inner_with_tracež   s    (    (
   t   __name__t
   __module__t	   greentestt   skipOnPurePythonR   R   R#   R-   R.   R0   (    (    (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyR   2   s   "$	t   __main__(   t
   __future__R    R   R'   t   unittestt   gevent.threadR   t   gevent.testingt   testingR3   R%   t   TestCaseR   R1   t   main(    (    (    sG   lib/python2.7/site-packages/gevent/tests/test__threading_vs_settrace.pyt   <module>   s   )p