o
    Á¿ió  ã                   @   s*   d dl Z eƒ Zdd„ Zdd„ Zdd„ ZdS )é    Nc                 C   s   t   | t j¡ t  | ¡ d S ©N)ÚsignalÚSIG_DFLÚraise_signal)ÚsignumÚframe© r   úR/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/utils/signals.pyÚ_raise_default   s   r
   c                 C   s&   | t v rdS t | t¡ t  | ¡ dS )zPInstall a base handler that exits the process after all other handlers complete.N)Ú_exit_handlers_installedr   r
   Úadd)Úsigr   r   r	   Ú_install_exit_handler   s   r   c                    sr   t  | ¡‰| t jt jfv rtˆƒst| ƒ t  | ¡‰‡ ‡fdd„}tˆƒr-ˆˆ ks-ˆ|kr3t   | ˆ ¡S t   | |¡S )ae  
    Returns a signal of type `sig` with function `f`, if there are
    no previously defined signals.

    Else, wraps the given signal with the previously defined one,
    so no signals are overridden.

    For SIGTERM and SIGINT, automatically ensures the process exits after
    all handlers complete by installing a base exit handler on first use.
    c                     s,   ˆ | i |¤Ž ˆd urˆ| i |¤Ž d S d S r   r   )ÚargsÚkwargs©ÚfÚ
old_signalr   r	   Úwrap_signals)   s   ÿz#handle_signal.<locals>.wrap_signals)r   Ú	getsignalÚSIGTERMÚSIGINTÚcallabler   )r   r   r   r   r   r	   Úhandle_signal   s   

r   )r   Úsetr   r
   r   r   r   r   r   r	   Ú<module>   s
    
