§
    ’tnis  ã                   ót   — d dl Z d dlZd dlmZmZ d dlZd dlmZ d dlm	Z	 e	rd dlm
Z
 dZ G d„ d¦  «        ZdS )	é    N)ÚThreadÚLock)Úlogger)ÚTYPE_CHECKING)ÚOptionalé
   c                   ó~   — e Zd ZdZdZ	 ddddeddfd	„Zdd
„Zdd„Zdd„Z	dd„Z
defd„Zedefd„¦   «         Zdd„ZdS )Ú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.
    zsentry.monitorr   Ú	transportzsentry_sdk.transport.TransportÚintervalÚreturnNc                 óŽ   — || _         || _        d| _        d| _        d | _        t          ¦   «         | _        d | _        d| _        d S )NTr   )	r   r   Ú_healthyÚ_downsample_factorÚ_threadr   Ú_thread_lockÚ_thread_for_pidÚ_running)Úselfr   r   s      úO/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/monitor.pyÚ__init__zMonitor.__init__   sH   € ð <EˆŒØ'ˆŒàˆŒØ'(ˆÔà+/ˆŒÝ ™FœFˆÔØ04ˆÔØˆŒˆˆó    c                 óè  ‡ — ‰ j         t          j        ¦   «         k    r	‰ j        dS ‰ j        5  ‰ j         t          j        ¦   «         k    r‰ j        	 ddd¦  «         dS dˆ fd„}t          ‰ j        |¬¦  «        }d|_        	 |                     ¦   «          n## t          $ r d‰ _
        Y ddd¦  «         dS w xY w|‰ _        t          j        ¦   «         ‰ _         ddd¦  «         n# 1 swxY w Y   dS )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.
        Nr   c                  ó   •— ‰ j         r=t          j        ‰ j        ¦  «         ‰ j         r‰                      ¦   «          ‰ j         °;d S d S ©N)r   ÚtimeÚsleepr   Úrun©r   s   €r   r   z(Monitor._ensure_running.<locals>._thread7   sV   ø€ Ø”mð #Ý”J˜tœ}Ñ-Ô-Ð-Ø”}ð #ØŸš™
œ
˜
ð ”mð #ð #ð #ð #ð #r   )ÚnameÚtargetTF©r   N)r   ÚosÚgetpidr   r   r   r    ÚdaemonÚstartÚRuntimeErrorr   )r   r   Úthreads   `  r   Ú_ensure_runningzMonitor._ensure_running(   s…  ø€ ð Ô¥2¤9¡;¤;Ò.Ð.°4´<Ð3KØ4àÔð 	/ð 	/ØÔ#¥r¤y¡{¤{Ò2Ð2°t´|Ð7OØð	/ð 	/ð 	/ñ 	/ô 	/ð 	/ð 	/ð 	/ð#ð #ð #ð #ð #ð #õ  ¤°7Ð;Ñ;Ô;ˆFØ ˆFŒMðØ—’‘”øÝð ð ð ð !&”Øð%	/ð 	/ð 	/ñ 	/ô 	/ð 	/ð 	/ð 	/ðøøøð "ˆDŒLÝ#%¤9¡;¤;ˆDÔ ð+	/ð 	/ð 	/ñ 	/ô 	/ð 	/ð 	/ð 	/ð 	/ð 	/ð 	/øøøð 	/ð 	/ð 	/ð 	/ð. ˆts;   ®%C'Á #C'ÂBÂC'ÂB9Â*C'Â8B9Â9"C'Ã'C+Ã.C+c                 óV   — |                       ¦   «          |                      ¦   «          d S r   )Úcheck_healthÚset_downsample_factorr   s    r   r   zMonitor.runL   s,   € Ø×ÒÑÔÐØ×"Ò"Ñ$Ô$Ð$Ð$Ð$r   c                 óØ   — | j         r(| j        dk    rt          j        d¦  «         d| _        d S | j        t
          k     r| xj        dz  c_        t          j        d| j        ¦  «         d S )Nr   z=[Monitor] health check positive, reverting to normal samplingé   zA[Monitor] health check negative, downsampling with a factor of %d)r   r   r   ÚdebugÚdownsample_factorÚMAX_DOWNSAMPLE_FACTORr   s    r   r,   zMonitor.set_downsample_factorP   s‹   € ØŒ=ð 	ØÔ&¨Ò*Ð*Ý”ØSñô ð ð '(ˆDÔ#Ð#Ð#àÔ%Õ(=Ò=Ð=ØÐ'Ô'¨1Ñ,Ð'Ô'ÝŒLØSØÔ'ñô ð ð ð r   c                 óB   — | j                              ¦   «         | _        dS )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_healthyr   r   s    r   r+   zMonitor.check_health_   s   € ð œ×1Ò1Ñ3Ô3ˆŒˆˆr   c                 ó8   — |                       ¦   «          | j        S r   )r)   r   r   s    r   r3   zMonitor.is_healthyg   s   € Ø×ÒÑÔÐØŒ}Ðr   c                 ó8   — |                       ¦   «          | j        S r   )r)   r   r   s    r   r0   zMonitor.downsample_factork   s   € à×ÒÑÔÐØÔ&Ð&r   c                 ó   — d| _         d S )NF)r   r   s    r   ÚkillzMonitor.killp   s   € ØˆŒˆˆr   )r   r"   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    Úfloatr   r)   r   r,   r+   Úboolr3   ÚpropertyÚintr0   r7   © r   r   r
   r
      s  € € € € € ðð ð €Dð NPðð Ø9ðØEJðà	ðð ð ð ð"ð "ð "ð "ðH%ð %ð %ð %ðð ð ð ð4ð 4ð 4ð 4ð˜Dð ð ð ð ð ð' 3ð 'ð 'ð 'ñ „Xð'ðð ð ð ð ð r   r
   )r#   r   Ú	threadingr   r   Ú
sentry_sdkÚsentry_sdk.utilsr   Útypingr   r   r1   r
   r@   r   r   ú<module>rE      s½   ðØ 	€	€	€	Ø €€€Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #à  Ð  Ð  Ð  Ð  Ð  àð  ØÐÐÐÐÐð Ð ð`ð `ð `ð `ð `ñ `ô `ð `ð `ð `r   