Viewing File: /opt/hc_python/lib/python3.12/site-packages/sentry_sdk/__pycache__/monitor.cpython-312.pyc
�
h0i7 � �l � d dl Z d dlZd dlmZmZ d dlZd dlmZ d dlm Z e rd dlm
Z
dZ G d� d� Zy) � N)�Thread�Lock)�logger)�
TYPE_CHECKING)�Optional�
c �P � e Zd ZdZdZdd�Zd� Zd� Zd� Zd� Z d� Z
ed � � Zd
� Z
y)
�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.monitorc � � || _ || _ d| _ d| _ d | _ t � | _ d | _ d| _ y )NTr ) � transport�interval�_healthy�_downsample_factor�_threadr �_thread_lock�_thread_for_pid�_running)�selfr r
s �A/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/monitor.py�__init__zMonitor.__init__ s? � �"��� ��
���
�"#������ �F���#�����
� c � � � � j t j � k( r
� j �y� j 5 � j t j � k( r� j �
ddd� y� fd�}t � j |�� }d|_ |j � |� _ t j � � _ ddd� y# t $ r d� _
Y ddd� yw xY w# 1 sw Y yxY w)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 � �� � j rIt j � j � � j r� j � � j r�Hy y �N)r �time�sleepr
�run�r s �r r z(Monitor._ensure_running.<locals>._thread7 s3 �� ��m�m��J�J�t�}�}�-��}�}����
� �m�mr )�name�targetTF)r �os�getpidr r r r �daemon�start�RuntimeErrorr )r r �threads ` r �_ensure_runningzMonitor._ensure_running'