o
    0 i                     @   s  d dl Z d dlZd dlmZ d dlmZmZ d dlmZm	Z	 d dl
Z
d dlmZ d dlmZmZ d dlmZmZmZmZ d dlmZ errd d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ ededef dZededZG dd deZdd Z dd Z!dd Z"dS )    Nwraps)Threadcurrent_thread)ThreadPoolExecutorFuture)Integrationuse_isolation_scope	use_scope)event_from_exceptioncapture_internal_exceptionsloggerreraise)TYPE_CHECKING)Any)TypeVar)Callable)Optional)ExcInfoF.)boundTc                   @   s&   e Zd ZdZdddZedd ZdS )	ThreadingIntegration	threadingNTc                 C   s.   |d ur	t d || _|d ur|| _d S d S )NzLDeprecated: propagate_hub is deprecated. This will be removed in the future.)r   warningpropagate_scope)selfZpropagate_hubr    r   m/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/threading.py__init__"   s   
zThreadingIntegration.__init__c                     s   t jzddlm}  dd l}|j}W n ty   d } d }Y nw tjdk o8|d uo8|dk o8| d uo8| dko8| dk  t	 fdd}|t _t
tj t_d S )	Nr   )VERSION)   	   z4.0.0)r"   r   )   r   c                    s   t  t}|d u r| g|R i |S |jr8 r+tjddd t  }t  }nt  	 }t  	 }nd }d }t
  t||t| jd| j}|| _W d    n1 sYw   Y  | g|R i |S )NaV  There is a known issue with Django channels 2.x and 3.x when using Python 3.8 or older. (Async support is emulated using threads and some Sentry data may be leaked between those threads.) Please either upgrade to Django channels 4.0+, use Django's async features available in Django 3.1+ instead of Django channels, or upgrade to Python 3.9+.   )
stacklevel__func__)
sentry_sdk
get_clientget_integrationr   r   warningswarnget_isolation_scopeget_current_scopeforkr   	_wrap_rungetattrrun)r   akwintegrationisolation_scopecurrent_scopeZnew_runis_async_emulated_with_threadsZ	old_startr   r   sentry_startI   s0   
z5ThreadingIntegration.setup_once.<locals>.sentry_start)r   startdjangor!   channels__version__ImportErrorsysversion_infor    _wrap_threadpool_executor_submitr   submit)Zdjango_versionr=   Zchannels_versionr:   r   r8   r   
setup_once2   s4   

	)
zThreadingIntegration.setup_once)NT)__name__
__module____qualname__
identifierr    staticmethodrD   r   r   r   r   r      s
    
r   c                    s   t  fdd}|S )Nc               	      s    fdd}d urEd urEt ' t | W  d    W  d    S 1 s.w   Y  W d    d S 1 s>w   Y  d S | S )Nc                     sF   zt  } | g dd  R i W S  ty"   tt   Y d S w )N   )r   	Exceptionr   _capture_exception)r   )r3   r4   old_run_funcr   r   _run_old_run_func~   s    z1_wrap_run.<locals>.run.<locals>._run_old_run_funcr	   )r3   r4   rN   current_scope_to_useisolation_scope_to_userM   )r3   r4   r   r2   {   s   

"z_wrap_run.<locals>.runr   )rQ   rP   rM   r2   r   rO   r   r0   y   s   r0   c                    s   t   fdd}|S )zB
    Wrap submit call to propagate scopes on task submission.
    c                    s   t  t}|d u r| g|R i |S |jr%r%t  t   n|jr5t   t    nd d   fdd}| |g|R i |S )Nc               	      s   d ur> d ur>t * t  | i |W  d    W  d    S 1 s*w   Y  W d    n1 s9w   Y  | i |S )Nr	   )argskwargsr7   fnr6   r   r   
wrapped_fn   s   

zK_wrap_threadpool_executor_submit.<locals>.sentry_submit.<locals>.wrapped_fn)r(   r)   r*   r   r   r-   r.   r/   )r   rU   rR   rS   r5   rV   funcr9   rT   r   sentry_submit   s   

	z7_wrap_threadpool_executor_submit.<locals>.sentry_submitr   )rX   r9   rY   r   rW   r   rB      s   rB   c                  C   sJ   t  } t }|td ur#t| |jdddd\}}tj||d | S )Nr   F)typeZhandled)Zclient_optionsZ	mechanism)hint)	r@   exc_infor(   r)   r*   r   r   optionsZcapture_event)r\   clienteventr[   r   r   r   rL      s   
rL   )#r@   r+   	functoolsr   r   r   r   concurrent.futuresr   r   r(   Zsentry_sdk.integrationsr   Zsentry_sdk.scoper
   r   Zsentry_sdk.utilsr   r   r   r   typingr   r   r   r   r   Zsentry_sdk._typesr   r   r   r   r0   rB   rL   r   r   r   r   <module>   s,    Z%