
    \e                         d Z ddlZddlZddlmZ ddlmZ  ej                  d      Z ej                  d      Z e	eef      Z
 eg d      Zd Z	 	 dd	Zd
 Z G d de      Zd Zy)z6
Eventlet utils helper module.

.. versionadded:: 1.3
    N)importutils)	timeutilseventletzeventlet.patcher)__builtin__MySQLdbospsycopgselectsocketthreadtimec                      t         st        j                  S t        j	                  d      } | rt
        j                  S t        j                  S )zGet the current thread.

    If eventlet is used to monkey-patch the threading module, return the
    current eventlet greenthread. Otherwise, return the current Python thread.

    .. versionadded:: 1.5
    r   )EVENTLET_AVAILABLE	threadingcurrent_thread_patcheris_monkey_patched	_eventlet
getcurrent)green_threadeds    :/usr/lib/python3/dist-packages/oslo_utils/eventletutils.pyfetch_current_thread_functorr   -   s>     '''!33H='''+++    c                     | st         j                         }nSt               }| D ]D  }|dk(  r|j                  t                |t         vrt	        d|z        |j                  |       F t        r}	 t        t        j                        }|r`g }t        |      D ])  }t        j                  |      r|j                  |       + |r$t        j                  d|d|dt         d       y	y	y	y	# t        $ r d}Y qw xY w)
a  Warns if eventlet is being used without patching provided modules.

    :param expected_patched_modules: list of modules to check to ensure that
                                     they are patched (and to warn if they
                                     are not); these names should correspond
                                     to the names passed into the eventlet
                                     monkey_patch() routine. If not provided
                                     then *all* the modules that could be
                                     patched are checked. The currently valid
                                     selection is one or multiple of
                                     ['MySQLdb', '__builtin__', 'all', 'os',
                                     'psycopg', 'select', 'socket', 'thread',
                                     'time'] (where 'all' has an inherent
                                     special meaning).
    :type expected_patched_modules: list/tuple/iterable
    :param what: string to merge into the warnings message to identify
                 what is being checked (used in forming the emitted warnings
                 message).
    :type what: string
    allz1Unknown module '%s' requested to check if patchedTz=It is highly recommended that when eventlet is used that the z' modules are monkey patched when using z8 (to avoid spurious or unexpected lock-ups and/or hangs)   )
stacklevelN)
_ALL_PATCHcopysetupdate
ValueErroraddr   boolr   already_patchedAttributeErrorsortedr   appendwarningswarnRuntimeWarning)expected_patched_moduleswhatexpanded_patched_modulesmmaybe_patchednot_patcheds         r   warn_eventlet_not_patchedr2   E   s   , $#-??#4 #&5 ) 	4AEz(//
;J&$ &356&7 8 8 -003	4 	! !!9!9:M K45 *11!4&&q)*  3>t	E
 -<  !   	! !M		!s   2C/ /C=<C=c                 :    t         yt         j                  |       S )zDetermines safely is eventlet patching for module enabled or not
    :param module: String, module name
    :return Bool: True if module is patched, False otherwise
    F)r   r   )modules    r   r   r      s     %%f--r   c                   @     e Zd ZdZ fdZd Zd ZeZd ZddZ	 xZ
S )EventletEventzA class that provides consistent eventlet/threading Event API.

    This wraps the eventlet.event.Event class to have the same API as
    the standard threading.Event object.
    c                 J    t         t        |           | j                          y N)superr6   __init__clear)selfargskwargs	__class__s      r   r:   zEventletEvent.__init__   s    mT+-

r   c                 t    t        | dd      r+d| _        t        j                  j	                         | _        y y )N_setTF)getattrrA   r   eventEvent_eventr<   s    r   r;   zEventletEvent.clear   s.    4&DI#////1DK 'r   c                     | j                   S r8   )rA   rF   s    r   is_setzEventletEvent.is_set   s    yyr   c                 b    | j                   s#d| _         | j                  j                  d       y y )NT)rA   rE   sendrF   s    r   r    zEventletEvent.set   s'    yyDIKKT" r   c                 n   t        j                  |      5 }	 | j                  }t        j                  j                  |j                  d      d      5  |j                          || j                  ur
	 d d d        f	 d d d        | j                         cd d d        S # 1 sw Y   "xY w# 1 sw Y   y xY w)NT)return_noneF)	r   	StopWatchrE   r   timeoutTimeoutleftoverwaitrH   )r<   rN   swrC   s       r   rQ   zEventletEvent.wait   s      ) 	%R&&..r{{t{/L/46 !JJLDKK/ 	! ! 0!
 {{}	% 	%! !	% 	%s)   >B+ B4	B+>B+B(	$B++B4r8   )__name__
__module____qualname____doc__r:   r;   rH   isSetr    rQ   __classcell__)r?   s   @r   r6   r6      s(    
2
 E#
	%r   r6   c                  T    t        d      r
t               S t        j                         S )Nr   )r   r6   r   rD    r   r   rD   rD      s    "  r   )Nzthis library)rV   r   r)   
oslo_utilsr   r   
try_importr   r   r   r   	frozensetr   r   r2   r   objectr6   rD   rZ   r   r   <module>r_      s   "   "   #K"":.	!;!!"45
 )X./   I J
,0 8<#1><B."%F "%J!r   