
    tni                     ^   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r@d 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                   Z ede          Z G d de          Z	 	 	 	 	 	 	 	 d dZ ddde!ddf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                   B    e Zd ZdZ	 d
dddeddfdZedd	            ZdS )ThreadingIntegration	threadingNTpropagate_hubzOptional[bool]propagate_scopereturnc                 V    |t          j        d           || _        |	|| _        d S d S )NzLDeprecated: propagate_hub is deprecated. This will be removed in the future.)r   warningr   )selfr   r   s      ^/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/integrations/threading.py__init__zThreadingIntegration.__init__"   sG     $N^    /$#0D    %$    c                  \   t           j        	 ddlm}  dd l}|j        }n# t          $ r d } d }Y nw xY wt          j        dk     o|d uo|dk     o| d uo| dk    o| dk     t                    dfd            }|t           _        t          t          j                  t          _        d S )Nr   )VERSION)   	   z4.0.0)r(   r   )   r   r"   r   ar   kwr   c           
      f   t          j                                        t                    }| | g|R i |S |j        rr=t          j        dd           t          j                    }t          j                    }nOt          j                    	                                }t          j                    	                                }nd }d }t                      5  t          ||t          | j        d| j                            }|| _        d d d            n# 1 swxY w 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"   r+   r,   integrationisolation_scopecurrent_scopenew_runis_async_emulated_with_threads	old_starts	          r#   sentry_startz5ThreadingIntegration.setup_once.<locals>.sentry_startI   s   $/11AABVWWK" y0000R000* %1 JMj $%    '1&D&F&FO$.$@$B$BMM '1&D&F&F&K&K&M&MO$.$@$B$B$G$G$I$IMM"& $ -.. # ###!DHj$(;; 
 ## # # # # # # # # # # # # # # 9T,A,,,,,,s   2DD #D )r"   r   r+   r   r,   r   r   r   )r   startdjangor'   channels__version__ImportErrorsysversion_infor    _wrap_threadpool_executor_submitr   submit)django_versionrE   channels_versionrB   r@   rA   s       @@r#   
setup_oncezThreadingIntegration.setup_once3   s    L		$888888OOO'3 	$ 	$ 	$!N#	$
 v% ( ,( 7*( d*( &(	(
 ' 	' 
y		&	- &	- &	- &	- &	- &	- 
	&	-P $$D%'E%
 %
!!!s   " 33)NT)r   N)__name__
__module____qualname__
identifierboolr$   staticmethodrN    r%   r#   r   r      sw        J OS1 1-1GK1	1 1 1 1" A
 A
 A
 \A
 A
 A
r%   r   isolation_scope_to_useOptional[sentry_sdk.Scope]current_scope_to_useold_run_funcr   c                 F     t                    d fd            }|S )Nr+   r   r,   r   c                      d fd}jht                    5  t                    5   |            cd d d            cd d d            S # 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S  |            S )Nr   r   c                      	 t                      }  | gdd          R i S # t          $ r t          t                        Y d S w xY w)N   )r   	Exceptionr   _capture_exception)r"   r+   r,   rY   s    r#   _run_old_run_funcz1_wrap_run.<locals>.run.<locals>._run_old_run_func   sq    /%''#|D71QRR5777B777 / / /+--...../s   !% AA)r   r   r
   )r+   r,   r`   rX   rV   rY   s   `` r#   r;   z_wrap_run.<locals>.run}   s\   	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ "-2F2R$%;<< / /344 / /,,../ / / / / / // / / / / / / // / / / / / / / // / / / / / / / / / / / / / / / / / %$&&&s3   A+
AA+A	A+A	A++A/2A/)r+   r   r,   r   r   r   r   )rV   rX   rY   r;   s   ``` r#   r9   r9   x   sI    
 <' ' ' ' ' ' ' ' Jr%   funczCallable[..., Future[T]]r@   c                 V     t                     	 	 	 	 	 	 	 	 	 	 d fd
            }|S )zB
    Wrap submit call to propagate scopes on task submission.
    r"   r   fnCallable[..., T]argsr   kwargsr   	Future[T]c                    t          j                                        t                    }| | g|R i |S |j        r)	r't          j                    t          j                    nV|j        rKt          j                                                    t          j                                                    nd d dfd} | |g|R i |S )Nre   r   rf   r   c                      ect                    5  t                    5   | i |cd d d            cd d d            S # 1 swxY w Y   	 d d d            n# 1 swxY w Y    | i |S )Nr
   )re   rf   r>   rc   r=   s     r#   
wrapped_fnzK_wrap_threadpool_executor_submit.<locals>.sentry_submit.<locals>.wrapped_fn   s*   *}/H(99 3 3"=11 3 3!r426223 3 3 3 3 3 33 3 3 3 3 3 3 33 3 3 3 3 3 3 3 33 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2t&v&&&s3   AAAA
	
AA
	AA"%A")re   r   rf   r   r   r   )r1   r2   r3   r   r   r6   r7   r8   )
r"   rc   re   rf   r<   rj   r>   r=   ra   r@   s
    `    @@r#   sentry_submitz7_wrap_threadpool_executor_submit.<locals>.sentry_submit   s    !+--==>RSS4b242226222& 	!+I 	!(<>>O&8::MM( 	!(<>>CCEEO&8::??AAMM"O M	' 	' 	' 	' 	' 	' 	' 	' tD*6t666v666r%   )
r"   r   rc   rd   re   r   rf   r   r   rg   r   )ra   r@   rk   s   `` r#   rJ   rJ      so     4[[7"77 7 	7
 
7 7 7 7 7 7 [7< r%   r   c                      t          j                    } t          j                    }|                    t
                    3t          | |j        ddd          \  }}t          j        ||           | S )Nr   F)typehandled)client_options	mechanism)hint)	rH   exc_infor1   r2   r3   r   r   optionscapture_event)rr   clienteventrq   s       r#   r_   r_      sx    |~~H"$$F233?*!>*u==
 
 
t
 	 T2222Or%   )rV   rW   rX   rW   rY   r   r   r   )r   r   )$rH   r4   	functoolsr   r   r   r   concurrent.futuresr   r   r1   sentry_sdk.integrationsr	   sentry_sdk.scoper   r   sentry_sdk.utilsr   r   r   r   typingr   r   r   r   r   sentry_sdk._typesr   r   r   r   r9   rS   rJ   r_   rU   r%   r#   <module>r~      s(   



        , , , , , , , , 9 9 9 9 9 9 9 9     / / / / / / ; ; ; ; ; ; ; ;            !           	 ))))))8CH-...A3AV
 V
 V
 V
 V
; V
 V
 V
r86  		   0&
$&FJ&& & & &R     r%   