U
    Ã@Ûf³  ã                   @   sÒ   d Z ddlZddlZddlZddlZddlZddddddd	d
ddddgZe d¡ZG dd„ dƒZ	d!dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd"dd„Zd#dd„Zd$dd
„Zd%dd„Zd&dd	„Zd'd d„ZdS )(zeThe debug module contains utilities and functions for better
debugging Eventlet-powered applications.é    NÚspewÚunspewÚformat_hub_listenersÚformat_hub_timersÚhub_listener_stacksÚhub_exceptionsÚtpool_exceptionsÚhub_prevent_multiple_readersÚhub_timer_stacksÚhub_blocking_detectionÚformat_asyncio_infoÚformat_threads_infoz\W+c                   @   s   e Zd Zddd„Zdd„ ZdS )ÚSpewNTc                 C   s   || _ || _d S )N©Útrace_namesÚshow_values)Úselfr   r   © r   úH/var/www/html/chatgpt/venv/lib/python3.8/site-packages/eventlet/debug.pyÚ__init__   s    zSpew.__init__c                 C   sN  |dkrJ|j }d|jkr\|jd }| d¡s8| d¡rD|d d… }|jd }t ||¡}nBd}zt |¡}|| }W n& tk
rœ   d|jj	|j
f }Y nX | jd ks´|| jkrJtd	||| ¡ f ƒ | jsÔ| S g }	t |¡}
|
D ]J}||jkr|	 d
||j| f ¡ ||jkræ|	 d
||j| f ¡ qæ|	rJtdd |	¡ ƒ | S )NÚlineÚ__file__z.pycz.pyoéÿÿÿÿÚ__name__z	[unknown]z,Unknown code named [%s].  VM instruction #%dz	%s:%s: %sz%s=%rz	%sú )Úf_linenoÚ	f_globalsÚendswithÚ	linecacheÚgetlineÚinspectÚgetsourcelinesÚOSErrorÚf_codeÚco_nameÚf_lastir   ÚprintÚrstripr   Ú_token_splitterÚsplitÚappendÚf_localsÚjoin)r   ÚframeÚeventÚargÚlinenoÚfilenameÚnamer   ÚsrcÚdetailsÚtokensÚtokr   r   r   Ú__call__   sB    



ÿ

 ÿ

zSpew.__call__)NT)r   Ú
__module__Ú__qualname__r   r7   r   r   r   r   r      s   
r   Fc                 C   s   t  t| |ƒ¡ dS )zpInstall a trace hook which writes incredibly detailed logs
    about what code is being executed to stdout.
    N)ÚsysÚsettracer   r   r   r   r   r   ;   s    c                   C   s   t  d¡ dS )z-Remove the trace hook installed by spew.
    N)r:   r;   r   r   r   r   r   B   s    c                  C   sh   ddl m}  |  ¡ }dg}| ¡ D ]}| t|ƒ¡ q"| d¡ | ¡ D ]}| t|ƒ¡ qHtj 	|¡S )zã Returns a formatted string of the current listeners on the current
    hub.  This can be useful in determining what's going on in the event system,
    especially when used in conjunction with :func:`hub_listener_stacks`.
    r   ©ÚhubszREADERS:zWRITERS:)
Úeventletr=   Úget_hubZget_readersr*   ÚreprZget_writersÚosÚlinesepr,   ©r=   ÚhubÚresultÚlr   r   r   r   H   s    
c                  C   sF   ddl } |  ¡ }dg}| t|ƒ¡ | d| j ¡ › ¡ tj |¡S )zË Returns a formatted string of the asyncio info.
    This can be useful in determining what's going on in the asyncio event
    loop system, especially when used in conjunction with the asyncio hub.
    r   NzTASKS:zEVENTLOOP: )	ÚasyncioÚ	all_tasksr*   r@   ÚeventsÚget_event_looprA   rB   r,   )rG   ÚtasksrE   r   r   r   r   X   s    c                  C   s.   ddl } | j}dg}| t|ƒ¡ tj |¡S )z· Returns a formatted string of the threads info.
    This can be useful in determining what's going on with created threads,
    especially when used in conjunction with greenlet
    r   NzTHREADS:)Ú	threadingÚ_activer*   r@   rA   rB   r,   )rL   ÚthreadsrE   r   r   r   r   e   s
    c                  C   s@   ddl m}  |  ¡ }dg}|jD ]}| t|ƒ¡ q tj |¡S )zÝ Returns a formatted string of the current timers on the current
    hub.  This can be useful in determining what's going on in the event system,
    especially when used in conjunction with :func:`hub_timer_stacks`.
    r   r<   zTIMERS:)	r>   r=   r?   Ztimersr*   r@   rA   rB   r,   rC   r   r   r   r   q   s    
c                 C   s   ddl m} | ¡  | ¡ dS )aV  Toggles whether or not the hub records the stack when clients register
    listeners on file descriptors.  This can be useful when trying to figure
    out what the hub is up to at any given moment.  To inspect the stacks
    of the current listeners, call :func:`format_hub_listeners` at critical
    junctures in the application logic.
    r   r<   N)r>   r=   r?   Zset_debug_listeners)Ústater=   r   r   r   r   ~   s    c                 C   s   ddl m} | |_dS )zÎToggles whether or not the hub records the stack when timers are set.
    To inspect the stacks of the current timers, call :func:`format_hub_timers`
    at critical junctures in the application logic.
    r   )ÚtimerN)Úeventlet.hubsrP   Z_g_debug)rO   rP   r   r   r   r
   ‰   s    Tc                 C   s@   ddl m}m} ddl m} | s6t|ƒ |jƒr6tdƒ‚| |_dS )a   Toggle prevention of multiple greenlets reading from a socket

    When multiple greenlets read from the same socket it is often hard
    to predict which greenlet will receive what data.  To achieve
    resource sharing consider using ``eventlet.pools.Pool`` instead.

    But if you really know what you are doing you can change the state
    to ``False`` to stop the hub from protecting against this mistake.
    r   )rD   r?   )rG   z5Multiple readers are not yet supported by asyncio hubN)rQ   rD   r?   rG   Ú
isinstanceZHubÚRuntimeErrorZg_prevent_multiple_readers)rO   rD   r?   rG   r   r   r   r	   ’   s
    
c                 C   s0   ddl m} | ¡  | ¡ ddl m} | |_dS )zToggles whether the hub prints exceptions that are raised from its
    timers.  This can be useful to see how greenthreads are terminating.
    r   r<   )Ú	greenpoolN)r>   r=   r?   Zset_timer_exceptionsrT   ÚDEBUG)rO   r=   rT   r   r   r   r   £   s    c                 C   s   ddl m} |  |_dS )z¡Toggles whether tpool itself prints exceptions that are raised from
    functions that are executed in it, in addition to raising them like
    it normally does.r   )ÚtpoolN)r>   rV   ZQUIET)rO   rV   r   r   r   r   ­   s    é   c                 C   s@   ddl m} |dkst‚| | ¡ _|| ¡ _| s<| ¡  ¡  dS )a¬  Toggles whether Eventlet makes an effort to detect blocking
    behavior in an application.

    It does this by telling the kernel to raise a SIGALARM after a
    short timeout, and clearing the timeout every time the hub
    greenlet is resumed.  Therefore, any code that runs for a long
    time without yielding to the hub will get interrupted by the
    blocking detector (don't use it in production!).

    The *resolution* argument governs how long the SIGALARM timeout
    waits in seconds.  The implementation uses :func:`signal.setitimer`
    and can be specified as a floating-point value.
    The shorter the resolution, the greater the chance of false
    positives.
    r   r<   N)r>   r=   ÚAssertionErrorr?   Zdebug_blockingZdebug_blocking_resolutionZblock_detect_post)rO   Ú
resolutionr=   r   r   r   r   µ   s    

)NF)F)F)T)T)F)FrW   )Ú__doc__rA   r:   r   Úrer    Ú__all__Úcompiler(   r   r   r   r   r   r   r   r   r
   r	   r   r   r   r   r   r   r   Ú<module>   s:       ü
(


	



