
    i                        d Z ddlmZ ddlmZ ddlZg Zg Zea	da
daej        Zej        Zd Zd Zd ZddlZd	 Zd
ddZdej        j        v rX eed          rLeej        _        e                    d           e                    d           e                    d           n?e                    d           e                    d           e                    d            ee e            eez   d          Zeez   ZdS )aj  
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
.. versionchanged:: 1.5a4
   Previously there was a backwards compatibility alias
   ``gevent.signal``, introduced in 1.1b4, that partly shadowed this
   module, confusing humans and static analysis tools alike. That alias
   has been removed. (See `gevent.signal_handler`.)
    )_NONE)copy_globalsNc                     | t           j        k    rt          |           S t          t          u rt          t           j                  at          S )z
    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.
    )_signalSIGCHLD_signal_getsignal_child_handler_INITIAL)	signalnums    8/usr/local/lib/python3.11/dist-packages/gevent/signal.py	getsignalr   &   sA     GO## +++ !!*7?;;    c                    | t           j        k    rt          | |          S |t           j        k    r.|t           j        k    rt          |          st          d          t          |           }|a|t           j        t           j        fv r7ddl	m
} t          | |            |            j                                         |S )aq  
    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.
    zKsignal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable objectr   get_hub)r   r   _signal_signalSIG_IGNSIG_DFLcallable	TypeErrorr   r
   
gevent.hubr   loopreset_sigchld)r   handlerold_handlerr   s       r   signalr   8   s    B GO##i111
 '/!!g&@&@RYIZIZ&@efffI&&KN7?GO444
 	'&&&&&y'***		$$&&&r   c                     t          t                    rsddlm}  t          dk    r0 | t
          t          t                    }|                                  | t          t          j	        d           }|                                 d S d S )Nr   )Greenlet)
r   r
   geventr   _child_wakeup_fd_write_child_signal_fd$_child_wakeup_fd_warn_on_full_bufferswitchr   r   )r   greenlets     r   _on_child_hookr&   q   s      	######q  x 6 0 DF FH OO8NGOTBB	 	r   c                 4   	 t           j                            | t          t          j        f                     d S # t          $ rQ}|s|j        t           j        j        vr,ddl	m
}  |                                dd d d            Y d }~d S Y d }~d S d }~ww xY w)Nr   r   set_wakeup_fd)r    os_writebytesr   r   OSErrorerrnoignored_errorsr   r   handle_error)fdwarn_on_full_bufferer   s       r   r"   r"      s    
F	UGO#56677777 F F F 	F!'1I"I"I******GII""?D$EEEEEEEEE #J"I"I"I"I"IFs   8< 
BA BBTr1   c               :    t          j        | |          }| a|a|S )a  
    Set the wakeup file descriptor to *fd*. When a signal is received, the signal number is
    written as a single byte into the *fd*. This can be used by a library to wakeup a poll
    or select call, allowing the signal to be fully processed.

    .. versionadded:: 25.8.1
    r3   )r   r(   r!   r#   )r0   r1   old_fds      r   r(   r(      s+     "2;NOOOF+>(Mr   waitpidr   r   r   r(    )names_to_ignoredunder_names_to_keep)__doc__gevent._utilr   r   r   r   r   __implements____extensions__r
   r!   r#   r   r   r	   r&   	gevent.osr    r"   r(   r)   hasattrappendglobals__imports____all__r7   r   r   <module>rD      s   ( + * * * * * % % % % % %     '+ $ %   $6 6 6r       
F 
F 
F 15      	(((WWWi-H-H(  .FI(###+&&&/**** (###+&&&/***l7GGII+9N+J024 4 4 >
)r   