Viewing File: /opt/hc_python/lib/python3.12/site-packages/sentry_sdk/__pycache__/monitor.cpython-312.pyc

�

_�*j���t�ddlZddlZddlZddlmZmZddlmZddlZddl	m
Z
erddlmZdZGd�d�Z
y)	�N)�Lock�Thread)�
TYPE_CHECKING)�logger)�Optional�
c��eZdZUdZdZded<ded<	dddd	ed
dfd�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zd
e
fd�Zed
efd��Zdd�Zy)�Monitorz�
    Performs health checks in a separate thread once every interval seconds
    and updates the internal state. Other parts of the SDK only read this state
    and act accordingly.
    zsentry.monitorzOptional[Thread]�_threadz
Optional[int]�_thread_for_pid�	transportzsentry_sdk.transport.Transport�interval�returnNc���||_||_d|_d|_d|_|j�t
td�r<tj|j
��d�fd�}tj|��yy)NTr�register_at_forkc�(����}|�|�yy�N�)�method�
weak_resets ��A/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/monitor.py�_reset_in_childz)Monitor.__init__.<locals>._reset_in_child5s���#����%��H�&�)�after_in_child�rN)r
r�_healthy�_downsample_factor�_running�_reset_thread_state�hasattr�os�weakref�
WeakMethodr)�selfr
rrrs    @r�__init__zMonitor.__init__ss���<E���'��
���
�'(�����
�� � �"��2�)�*� �+�+�D�,D�,D�E�J�
�

����?�+rc�>�d|_t�|_d|_yr)rr�_thread_lockr�r$s rrzMonitor._reset_thread_state<s����� �F���#��rc����jtj�k(r
�j�y�j5�jtj�k(r�j�
	ddd�yd�fd�}t�j|��}d|_	|j�|�_tj��_ddd�y#t$rd�_
Yddd�ywxYw#1swYyxYw)a-
        Check that the monitor has an active thread to run in, or create one if not.

        Note that this might fail (e.g. in Python 3.12 it's not possible to
        spawn new threads at interpreter shutdown). In that case self._running
        will be False after running this function.
        Nc����jrItj�j��jr�j	��jr�Hyyr)r�time�sleepr�runr(s�rrz(Monitor._ensure_running.<locals>._threadPs3����m�m��J�J�t�}�}�-��}�}����
��m�mr)�name�targetTFr)rr!�getpidrr'rr.�daemon�start�RuntimeErrorr)r$r�threads`  r�_ensure_runningzMonitor._ensure_runningAs�������2�9�9�;�.�4�<�<�3K��
�
�
��#�#�r�y�y�{�2�t�|�|�7O���
�
#�����7�;�F� �F�M�
�����"�D�L�#%�9�9�;�D� �+�.�� �
�!&��
��%�
�
���.�s5�/C0�4$C0�C�) C0�C-�"C0�,C-�-C0�0C9c�D�|j�|j�yr)�check_health�set_downsample_factorr(s rr-zMonitor.runes�������"�"�$rc��|jr,|jdkDrtjd�d|_y|jt
kr|xjdz
c_tjd|j�y)Nrz=[Monitor] health check positive, reverting to normal sampling�zA[Monitor] health check negative, downsampling with a factor of %d)rrr�debug�downsample_factor�MAX_DOWNSAMPLE_FACTORr(s rr8zMonitor.set_downsample_factorish���=�=��&�&��*����S��'(�D�#��%�%�(=�=��'�'�1�,�'��L�L�S��'�'�
rc�B�|jj�|_y)z�
        Perform the actual health checks,
        currently only checks if the transport is rate-limited.
        TODO: augment in the future with more checks.
        N)r
�
is_healthyrr(s rr7zMonitor.check_healthxs�����1�1�3��
rc�:�|j�|jSr)r5rr(s rr?zMonitor.is_healthy�s�������}�}�rc�:�|j�|jSr)r5rr(s rr<zMonitor.downsample_factor�s�������&�&�&rc��d|_y)NF)rr(s r�killzMonitor.kill�s	����
r)rr)�__name__�
__module__�__qualname__�__doc__r.�__annotations__�floatr%rr5r-r8r7�boolr?�property�intr<rCrrrr
r
s�����D�
��$�$�NP�@�9�@�EJ�@�	
�@�>$�
"�H%�
�4��D���'�3�'��'�rr
)r!r+r"�	threadingrr�typingr�
sentry_sdk�sentry_sdk.utilsrrr=r
rrr�<module>rQs4��	���"� ��#�����y�yr
Back to Directory File Manager