o
    i                     @   s^   d dl Z d dlZd dlZd dlmZ G dd dejZG dd deZG dd de j	d	Z
dS )
    N)Lockc                   @   s   e Zd ZdZdZdZdS )ServiceStatuszA Service status.stoppedrunningN)__name__
__module____qualname____doc__STOPPEDRUNNING r   r   L/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/service.pyr      s    r   c                       s*   e Zd Zdddeddf fddZ  ZS )ServiceStatusErrorservice_clsztype[Service]current_statusreturnNc                    s&   || _ tt| d|j|jf  d S )Nz%s is already in status %s)r   superr   __init__r   value)selfr   r   	__class__r   r   r      s   
zServiceStatusError.__init__)r   r   r   r   r   __classcell__r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdddZdd Zdd	 Zd
d Zdej	dej	ddfddZ
ejdej	dej	ddfddZdej	dej	ddfddZejdej	dej	ddfddZ	ddeje ddfddZdS )Servicez)A service that can be started or stopped.r   Nc                 C   s   t j| _t | _d S N)r   r
   statusr   _service_lockr   r   r   r   r         zService.__init__c                 C   sD   | j j}dd | j D }ddd | D }| d| dS )Nc                 S   s    i | ]\}}| d s||qS )_)
startswith.0kvr   r   r   
<dictcomp>$   s     z$Service.__repr__.<locals>.<dictcomp>z, c                 s   s"    | ]\}}| d |V  qdS )=Nr   r!   r   r   r   	<genexpr>%   s     z#Service.__repr__.<locals>.<genexpr>())r   r   __dict__itemsjoin)r   
class_nameattrs	attrs_strr   r   r   __repr__"   s   zService.__repr__c                 C   s   |    | S r   )startr   r   r   r   	__enter__(   s   zService.__enter__c                 C   s   |    |   d S r   )stopr,   )r   exc_type	exc_value	tracebackr   r   r   __exit__,   r   zService.__exit__argskwargsc                 O   ^   | j " | jtjkrt| j| j| j|i | tj| _W d   dS 1 s(w   Y  dS )zStart the service.N)r   r   r   r   r   r   _start_servicer   r8   r9   r   r   r   r1   0   s   
"zService.startc                 O      dS )zStart the service for real.

        This method uses the internal lock to be sure there's no race conditions and that the service is really started
        once start() returns.

        Nr   r<   r   r   r   r;   >       zService._start_servicec                 O   r:   )zStop the service.N)r   r   r   r
   r   r   _stop_servicer<   r   r   r   r3   K   s   
"zService.stopc                 O   r=   )zStop the service for real.

        This method uses the internal lock to be sure there's no race conditions and that the service is really stopped
        once start() returns.

        Nr   r<   r   r   r   r?   W   r>   zService._stop_servicetimeoutc                 C   r=   )zJoin the service once stopped.Nr   )r   r@   r   r   r   r,   d   r>   zService.join)r   Nr   )r   r   r   r	   r   r0   r2   r7   typingAnyr1   abcabstractmethodr;   r3   r?   Optionalfloatr,   r   r   r   r   r      sT    


r   )	metaclass)rC   enumrA   ddtrace.internal.threadsr   Enumr   RuntimeErrorr   ABCMetar   r   r   r   r   <module>   s    