ó
ĞH/\c           @@  s!  d  Z  d d l m Z d d l m Z d d l m Z d d l Z g  Z	 g  Z
 e a e j Z e j Z d „  Z d „  Z d „  Z d d l Z d	 e j j	 k r× e e d
 ƒ r× e e j _ e	 j d ƒ e	 j d ƒ n e
 j d ƒ e
 j d ƒ e e e ƒ  d e	 e
 d d ƒZ e	 e
 Z d S(   sW  
Cooperative implementation of special cases of :func:`signal.signal`.

This module is designed to work with libev's child watchers, as used
by default in :func:`gevent.os.fork` Note that each ``SIGCHLD`` handler
will be run in a new greenlet when the signal is delivered (just like
:class:`gevent.hub.signal`)

The implementations in this module are only monkey patched if
:func:`gevent.os.waitpid` is being used (the default) and if
:const:`signal.SIGCHLD` is available; see :func:`gevent.os.fork` for
information on configuring this not to be the case for advanced uses.

.. versionadded:: 1.1b4
i    (   t   absolute_import(   t   _NONE(   t   copy_globalsNc         C@  s;   |  t  j k r t |  ƒ St t k r7 t t  j ƒ a n  t S(   sÖ   
    Exactly the same as :func:`signal.getsignal` except where
    :const:`signal.SIGCHLD` is concerned.

    For :const:`signal.SIGCHLD`, this cooperates with :func:`signal`
    to provide consistent answers.
    (   t   _signalt   SIGCHLDt   _signal_getsignalt   _child_handlert   _INITIAL(   t	   signalnum(    (    s,   lib/python2.7/site-packages/gevent/signal.pyt	   getsignal"   s
    
c         C@  s´   |  t  j k r t |  | ƒ S| t  j k rV | t  j k rV t | ƒ rV t d ƒ ‚ n  t |  ƒ } | a | t  j t  j f k r° d d l	 m
 } t |  | ƒ | ƒ  j j ƒ  n  | S(   sq  
    Exactly the same as :func:`signal.signal` except where
    :const:`signal.SIGCHLD` is concerned.

    .. note::

       A :const:`signal.SIGCHLD` handler installed with this function
       will only be triggered for children that are forked using
       :func:`gevent.os.fork` (:func:`gevent.os.fork_and_watch`);
       children forked before monkey patching, or otherwise by the raw
       :func:`os.fork`, will not trigger the handler installed by this
       function. (It's unlikely that a SIGCHLD handler installed with
       the builtin :func:`signal.signal` would be triggered either;
       libev typically overwrites such a handler at the C level. At
       the very least, it's full of race conditions.)

    .. note::

        Use of ``SIG_IGN`` and ``SIG_DFL`` may also have race conditions
        with libev child watchers and the :mod:`gevent.subprocess` module.

    .. versionchanged:: 1.2a1
         If ``SIG_IGN`` or ``SIG_DFL`` are used to ignore ``SIGCHLD``, a
         future use of ``gevent.subprocess`` and libev child watchers
         will once again work. However, on Python 2, use of ``os.popen``
         will fail.

    .. versionchanged:: 1.1rc2
         Allow using ``SIG_IGN`` and ``SIG_DFL`` to reset and ignore ``SIGCHLD``.
         However, this allows the possibility of a race condition if ``gevent.subprocess``
         had already been used.
    sK   signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable objecti    (   t   get_hub(   R   R   t   _signal_signalt   SIG_IGNt   SIG_DFLt   callablet	   TypeErrorR	   R   t
   gevent.hubR
   t   loopt   reset_sigchld(   R   t   handlert   old_handlerR
   (    (    s,   lib/python2.7/site-packages/gevent/signal.pyt   signal4   s    !+c          C@  sB   t  t ƒ r> d d l m }  |  t t j d  ƒ } | j ƒ  n  d  S(   Ni    (   t   Greenlet(   R   R   t   geventR   R   R   t   Nonet   switch(   R   t   greenlet(    (    s,   lib/python2.7/site-packages/gevent/signal.pyt   _on_child_hookm   s    t   waitpidR   R   R	   t   names_to_ignoret   dunder_names_to_keep(    (   t   __doc__t
   __future__R    t   gevent._utilR   R   R   R   R   t   __implements__t   __extensions__R   R   R	   R   R   t	   gevent.osR   t   ost   hasattrt   appendt   globalst   __imports__t   __all__(    (    (    s,   lib/python2.7/site-packages/gevent/signal.pyt   <module>   s.   				9	!
	