
    !ni                          d Z ddlZddlZddlZddlZddlZg dZ ej                  d      Z G d d      Z	ddZ
d Zd	 Zd
 Zd Zd ZddZddZddZddZddZddZy)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                       e Zd ZddZd Zy)SpewNc                      || _         || _        y )Ntrace_namesshow_values)selfr   r   s      N/home/homepc/tiktok-worker/venv/lib/python3.12/site-packages/eventlet/debug.py__init__zSpew.__init__   s    &&    c                    |dk(  r|j                   }d|j                  v r\|j                  d   }|j                  d      s|j                  d      r|d d }|j                  d   }t        j                  ||      }n*d}	 t        j                  |      \  }}	|	dk(  rd	}	|||	z
     }| j                  || j                  v rt        |d|d|j                                | j                  s| S g }
t        j!                  |      }|D ]e  }||j                  v r#|
j#                  |d|j                  |          ||j$                  v sC|
j#                  |d|j$                  |          g |
rt        ddj'                  |
      z         | S # t        $ r) d
|j                  j                  |j                  fz  }Y w xY w)Nline__file__z.pycz.pyo__name__z	[unknown]r      z,Unknown code named [%s].  VM instruction #%d:z: =z	%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offsetdetailstokenstoks                r   __call__zSpew.__call__   s   F?^^FU__, ??:6%%f- ))&1'}Hz2 ((6:"	=")"8"8"?KC {!"v/D '443C3C+CT64;;=AB''K(..t4! MCeoo-#us7K'LMenn,#u~~c7J'KL	M
 &388G#445!  =I,,emmM= =D=s    'F .GG)NT)r   
__module____qualname__r   r?    r   r   r   r      s    '#r   r   c                 B    t        j                  t        | |             y)zpInstall a trace hook which writes incredibly detailed logs
    about what code is being executed to stdout.
    N)syssettracer   r   s     r   r   r   ?   s     LLk;/0r   c                  .    t        j                  d       y)z-Remove the trace hook installed by spew.
    N)rD   rE   rB   r   r   r   r   F   s     LLr   c                  P   ddl m}  | j                         }dg}|j                         D ]  }|j	                  t        |              |j	                  d       |j                         D ]  }|j	                  t        |              t        j                  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:)
eventletrI   get_hubget_readersr1   reprget_writersoslinesepr3   rI   hubresultls       r   r   r   L   s    
 
,,.C\F__ d1g
MM*__ d1g::??6""r   c                      ddl } | j                         }dg}|j                  t        |             |j                  d| j                  j                                 t        j                  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_tasksr1   rM   eventsget_event_looprO   rP   r3   )rV   tasksrS   s      r   r   r   \   s`    
 EZF
MM$u+
MMK = = ?@AB::??6""r   c                      ddl } | j                  }dg}|j                  t        |             t        j
                  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_activer1   rM   rO   rP   r3   )r\   threadsrS   s      r   r   r   i   s<    
 G\F
MM$w- ::??6""r   c                      ddl m}  | j                         }dg}|j                  D ]  }|j	                  t        |              t        j                  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   rH   zTIMERS:)	rJ   rI   rK   timersr1   rM   rO   rP   r3   rQ   s       r   r   r   u   sO    
 
,,.C[FZZ d1g::??6""r   c                 N    ddl m} |j                         j                  |        y)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   rH   N)rJ   rI   rK   set_debug_listeners)staterI   s     r   r   r      s     LLN&&u-r   c                     ddl m} | |_        y)zToggles 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.hubsre   _g_debug)rc   re   s     r   r   r      s    
 $ENr   c                 ~    ddl m}m} ddl m} | s&t	         |       |j
                        rt        d      | |_        y)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.

    It is important to note that this feature is a debug
    convenience. That's not a feature made to be integrated in a production
    code in some sort.

    **If you really know what you are doing** you can change the state
    to ``False`` to stop the hub from protecting against this mistake. Else
    we strongly discourage using this feature, or you should consider using it
    really carefully.

    You should be aware that disabling this prevention will be applied to
    your entire stack and not only to the context where you may find it useful,
    meaning that using this debug feature may have several significant
    unexpected side effects on your process, which could cause race conditions
    between your sockets and on all your I/O in general.

    You should also notice that this debug convenience is not supported
    by the Asyncio hub, which is the official plan for migrating off of
    eventlet. Using this feature will lock your migration path.
    r   )rR   rK   )rV   z5Multiple readers are not yet supported by asyncio hubN)rf   rR   rK   rV   
isinstanceHubRuntimeErrorg_prevent_multiple_readers)rc   rR   rK   rV   s       r   r
   r
      s0    4 +%Z	7;;7RSS%*C"r   c                 h    ddl m} |j                         j                  |        ddl m} | |_        y)zToggles whether the hub prints exceptions that are raised from its
    timers.  This can be useful to see how greenthreads are terminating.
    r   rH   )	greenpoolN)rJ   rI   rK   set_timer_exceptionsrn   DEBUG)rc   rI   rn   s      r   r   r      s%     LLN''."IOr   c                      ddl m} |  |_        y)zToggles 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)rJ   rr   QUIET)rc   rr   s     r   r	   r	      s     )EKr   c                     ddl m} |dkD  sJ | |j                         _        ||j                         _        | s|j                         j                          yy)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   rH   N)rJ   rI   rK   debug_blockingdebug_blocking_resolutionblock_detect_post)rc   
resolutionrI   s      r   r   r      sI      >>$)DLLN!/9DLLN,((* r   )NF)F)T)Fr   )__doc__rO   rD   r%   rer'   __all__compiler/   r   r   r   r   r   r   r   r   r   r
   r   r	   r   rB   r   r   <module>r}      s|   , 
 
  	 " "**V$) )X1# 
#	#
#.+B+r   