o
    Á¿iÚ  ã                   @   s†   d dl mZ d dlmZ d dlmZ G dd„ deƒZG dd„ deƒZG dd	„ d	eƒZ	d
e
fdd„Zddee dee d
dfdd„ZdS )é    )Úabsolute_import)ÚCallable)ÚOptionalc                   @   ó   e Zd ZdZdS )ÚuWSGIConfigErrorznuWSGI configuration error.

    This is raised when uwsgi configuration is incompatible with the library.
    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úJ/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/uwsgi.pyr      ó    r   c                   @   r   )ÚuWSGIConfigDeprecationWarningzæuWSGI configuration deprecation warning.

    This is raised when uwsgi configuration is incompatible with the library,
    and future versions of the library plans to raise an error and stop
    supporting the configuration.
    Nr   r   r   r   r   r      r   r   c                   @   r   )ÚuWSGIMasterProcessz$The process is uWSGI master process.Nr   r   r   r   r   r      r   r   Úreturnc               	   C   s2   zddl } | j d¡ W S  ttfy   Y dS w )an  Check if Python atexit handlers should be registered under uwsgi.

    Returns False if running under uwsgi with --skip-atexit, True otherwise.
    This respects the user's explicit request to skip atexit handlers, which
    is important because running complex operations (like HTTP uploads) during
    atexit can cause heap corruption during process shutdown.
    r   Núskip-atexitT)ÚuwsgiÚoptÚgetÚImportErrorÚAttributeError)r   r   r   r   Úshould_register_atexit   s   þr   NÚworker_callbackÚatexitc                    sN  zddl }W n
 ty   Y dS w t|dƒsd}t|ƒ‚|j d¡s2t|j d¡p*dƒs2d}t|ƒ‚t|dƒrT|jd	k rT|j d
¡sH|j d¡rT|j d¡sTd}t|ƒ‚|j	dkr¡|j d
¡s£| 
¡ dkr¥|j d¡sotdƒ‚| durŠzddl}W n ty„   tdƒ‚w | | ¡ ˆ duržt|ddƒ‰‡ ‡fdd„}||_tƒ ‚dS dS dS )z‘Check whetever uwsgi is running and what needs to be done.

    :param worker_callback: Callback function to call in uWSGI worker processes.
    r   Nr   z]Unable to access uwsgi options. Please make sure that the --import=ddtrace.auto option is setzenable-threadsÚthreadszVenable-threads option must be set to true, or a positive number of threads must be setÚversion_info)é   r   é   z	lazy-appsÚlazyr   zÆskip-atexit option must be set when lazy-apps or lazy is set for             uwsgi<2.0.30, see https://github.com/unbit/uwsgi/pull/2726. We plan             to raise an error in ddtrace 4.x release.é   Úmasterz>master option must be enabled when multiple processes are usedz:Running under uwsgi but uwsgidecorators cannot be importedr   c                      s4   zˆ ƒ  W n	 t y   Y nw ˆd urˆƒ  d S d S )N)Ú	Exceptionr   ©r   Úoriginal_atexitr   r   Ú_atexitb   s   
ÿ
ÿzcheck_uwsgi.<locals>._atexit)r   r   Úhasattrr   r   r   Úintr   r   ÚnumprocÚ	worker_idÚuwsgidecoratorsÚpostforkÚgetattrr   r   )r   r   r   Úmsgr*   r%   r   r#   r   Úcheck_uwsgi,   sL   ÿ
 ÿ

ÿ
ÿ
þ"	ÿ
	ãr.   )NN)Ú
__future__r   Útypingr   r   r"   r   ÚDeprecationWarningr   r   Úboolr   r.   r   r   r   r   Ú<module>   s    	$