§
    ŽpmaÖ  ã                   ó¾   — d dl mZmZmZ d dlmZmZ d dlZd dlm	Z	 dZ
d„ Z G d„ d¦  «        Z e¦   «         ad	„ Z G d
„ de¦  «        Zi ad„ Z G d„ de¦  «        ZdS )é    )ÚLockÚThreadÚBoundedSemaphore)ÚQueueÚEmptyN)ÚgetglobaluiÚSTOP_MONITORc                 óž   — t          |¦  «        D ]}|                      ¦   «          Œt          |¦  «        D ]}|                      ¦   «          ŒdS )zjBlock until `semaphore` gets back to its original state, ie all acquired
    resources have been released.N)ÚrangeÚacquireÚrelease)Ú	semaphoreÚoriginalstateÚis      ú1/usr/share/offlineimap3/offlineimap/threadutil.pyÚsemaphoreresetr      sf   € õ �=Ñ!Ô!ð ð ˆØ×ÒÑÔÐÐå�=Ñ!Ô!ð ð ˆØ×ÒÑÔÐÐðð ó    c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚaccountThreadsznStore the list of all threads in the software so it can be used to find out
    what's running and what's not.c                 ó:   — t          ¦   «         | _        g | _        d S ©N)r   ÚlockÚlist©Úselfs    r   Ú__init__zaccountThreads.__init__,   s   € Ý‘F”FˆŒ	ØˆŒ	ˆ	ˆ	r   c                 óz   — | j         5  | j                             |¦  «         d d d ¦  «         d S # 1 swxY w Y   d S r   )r   r   Úappend©r   Úthreads     r   ÚaddzaccountThreads.add0   ó„   € ØŒYð 	%ð 	%ØŒI×Ò˜VÑ$Ô$Ð$ð	%ð 	%ð 	%ñ 	%ô 	%ð 	%ð 	%ð 	%ð 	%ð 	%ð 	%ð 	%øøøð 	%ð 	%ð 	%ð 	%ð 	%ð 	%ó   ˆ0°4·4c                 óz   — | j         5  | j                             |¦  «         d d d ¦  «         d S # 1 swxY w Y   d S r   )r   r   Úremover   s     r   r%   zaccountThreads.remove4   r"   r#   c                 óÂ   — | j         5  t          | j        ¦  «        dk     r	 d d d ¦  «         d S | j                             ¦   «         cd d d ¦  «         S # 1 swxY w Y   d S )Né   )r   Úlenr   Úpopr   s    r   r)   zaccountThreads.pop8   s»   € ØŒYð 	#ð 	#Ý�4”9‰~Œ~ Ò!Ð!Øð	#ð 	#ð 	#ñ 	#ô 	#ð 	#ð 	#ð 	#ð ”9—=’=‘?”?ð	#ð 	#ð 	#ð 	#ñ 	#ô 	#ð 	#ð 	#ð 	#ð 	#ð 	#ð 	#øøøð 	#ð 	#ð 	#ð 	#ð 	#ð 	#s   ˆA¯AÁAÁAc                 ó^   — 	 |                       ¦   «         }|€d S |                     ¦   «          Œ-r   )r)   Újoinr   s     r   ÚwaitzaccountThreads.wait>   s0   € ð	Ø—X’X‘Z”ZˆFØˆ~Ø�Ø�KŠK‰MŒMˆMð		r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r%   r)   r,   © r   r   r   r   (   si   € € € € € ð&ð &ðð ð ð%ð %ð %ð%ð %ð %ð#ð #ð #ðð ð ð ð r   r   c                  ó¸  — t          ¦   «         } 	 	 t                               dd¦  «        }|j        �pt	          |j        t
          ¦  «        rt
          ‚|                      |¦  «         t          dt          |j        ¦  «        ›dt          |j        ¦  «        ›d�¦  «        ‚|j
        t          k    rdS |                      |¦  «         n# t          $ r Y nw xY wŒÌ)z�An infinite "monitoring" loop watching for finished ExitNotifyThread's.

    This one is supposed to run in the main thread.
    Té<   Nz$thread has 'exit_exception' set to 'z' [zC] but this value is unexpected and the ui did not stop the program.)r   ÚexitedThreadsÚgetÚexit_exceptionÚ
isinstanceÚ
SystemExitÚthreadExceptionÚAssertionErrorÚreprÚtypeÚexit_messager	   ÚthreadExitedr   )Úuir    s     r   Úmonitorr@   M   sÿ   € õ 
‰Œ€Bðð	õ #×&Ò& t¨RÑ0Ô0ˆFð Ô$Ð0Ý˜fÔ3µZÑ@Ô@ð %õ %Ð$Ø×"Ò" 6Ñ*Ô*Ð*å$�nõ '+¨6Ô+@Ñ&AÔ&AÐ&AÐ&AÅ4ÈÔH]ÑC^ÔC^ÐC^ÐC^ð&`ñ aô að að Ô$­Ò4Ð4Ø�à—’ Ñ'Ô'Ð'Ð'øÝð 	ð 	ð 	ØˆDð	øøøð=s   ‘B"C Â5C Ã
CÃCc                   ó\   ‡ — e Zd ZdZˆ fd„Zd„ Zdd„Zed„ ¦   «         Zed„ ¦   «         Z	ˆ xZ
S )	ÚExitNotifyThreadaË  This class is designed to alert a "monitor" to the fact that a
    thread has exited and to provide for the ability for it to find out
    why.  All instances are made daemon threads (setDaemon(True), so we
    bail out when the mainloop dies.

    The thread can set instance variables self.exit_message for a human
    readable reason of the thread exit.

    There is one instance of this class at runtime. The main thread waits for
    the monitor to end.c                 óœ   •—  t          t          | ¦  «        j        |i |¤Ž |                      d¦  «         d | _        d | _        d | _        d S )NT)ÚsuperrB   r   Ú	setDaemonr=   Ú	_exit_excÚ_exit_stacktrace)r   ÚargsÚkwargsÚ	__class__s      €r   r   zExitNotifyThread.__init__„   sW   ø€ Ø.�Õ Ñ%Ô%Ô.°Ð?¸Ð?Ð?Ð?ð 	�Š�tÑÔÐØ ˆÔØˆŒØ $ˆÔÐÐr   c                 óè   — 	 t          j        | ¦  «         n@# t          $ r3}t          j        ¦   «         }|                      ||¦  «         Y d}~nd}~ww xY wt                               | d¦  «         dS )z.Allow profiling of a run and store exceptions.NT)r   ÚrunÚ	ExceptionÚ	tracebackÚ
format_excÚset_exit_exceptionr4   Úput)r   ÚeÚtbs      r   rL   zExitNotifyThread.run�   sŠ   € ð	+ÝŒJ�tÑÔÐÐøÝð 	+ð 	+ð 	+åÔ%Ñ'Ô'ˆBØ×#Ò# A rÑ*Ô*Ð*Ð*Ð*Ð*Ð*Ð*øøøøð	+øøøõ
 	×Ò˜$ Ñ%Ô%Ð%Ð%Ð%s   ‚ —
A¡)AÁANc                 ó"   — || _         || _        dS )zbSets Exception and stacktrace of a thread, so that other
        threads can query its exit statusN)rF   rG   )r   ÚexcÚsts      r   rP   z#ExitNotifyThread.set_exit_exceptionš   s   € ð ˆŒØ "ˆÔÐÐr   c                 ó   — | j         S )zˆReturns the cause of the exit, one of:
        Exception() -- the thread aborted with this exception
        None -- normal termination.)rF   r   s    r   r6   zExitNotifyThread.exit_exception¡   s   € ð Œ~Ðr   c                 ó   — | j         S )z4Returns a string representing the stack trace if set)rG   r   s    r   Úexit_stacktracez ExitNotifyThread.exit_stacktrace©   s   € ð Ô$Ð$r   r   )r-   r.   r/   r0   r   rL   rP   Úpropertyr6   rY   Ú__classcell__©rJ   s   @r   rB   rB   x   s›   ø€ € € € € ð	ð 	ð%ð %ð %ð %ð %ð&ð &ð &ð#ð #ð #ð #ð ðð ñ „Xðð ð%ð %ñ „Xð%ð %ð %ð %ð %r   rB   c                 óJ   — | t           vrt          |¦  «        t           | <   dS dS )z³Initialize the instance-limited thread implementation.

    Run up to intancemax threads for the given limitNamespace. This allows to
    honor maxsyncaccounts and maxconnections.N)ÚlimitedNamespacesr   )ÚlimitNamespaceÚinstancemaxs     r   ÚinitInstanceLimitra   ·   s1   € ð Õ.Ð.Ð.Ý,<¸[Ñ,IÔ,IÕ˜.Ñ)Ð)Ð)ð /Ð.r   c                   ó*   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zˆ xZS )ÚInstanceLimitedThreadc                 óV   •— || _          t          t          | ¦  «        j        |i |¤Ž d S r   )r_   rD   rc   r   )r   r_   rH   rI   rJ   s       €r   r   zInstanceLimitedThread.__init__Ä   s4   ø€ Ø,ˆÔØ3�Õ# TÑ*Ô*Ô3°TÐD¸VÐDÐDÐDÐDÐDr   c                 ó‚   — t           | j                                      ¦   «          t                               | ¦  «         d S r   )r^   r_   r   rB   Ústartr   s    r   rf   zInstanceLimitedThread.startÈ   s8   € õ 	˜$Ô-Ô.×6Ò6Ñ8Ô8Ð8Ý×Ò˜tÑ$Ô$Ð$Ð$Ð$r   c                 óF  — 	 t                                | ¦  «         t          r8t          | j                 r(t          | j                                      ¦   «          d S d S d S # t          r7t          | j                 r&t          | j                                      ¦   «          w w w xY wr   )rB   rL   r^   r_   r   r   s    r   rL   zInstanceLimitedThread.runÏ   sµ   € ð	AÝ× Ò  Ñ&Ô&Ð&å ð AÕ%6°tÔ7JÔ%Kð AÝ! $Ô"5Ô6×>Ò>Ñ@Ô@Ð@Ð@Ð@ðAð Að Að AøÕ ð AÕ%6°tÔ7JÔ%Kð AÝ! $Ô"5Ô6×>Ò>Ñ@Ô@Ð@Ð@ðAð Aøøøs   ‚A ÁAB )r-   r.   r/   r   rf   rL   r[   r\   s   @r   rc   rc   Ã   sb   ø€ € € € € ðEð Eð Eð Eð Eð%ð %ð %ðAð Að Að Að Að Að Ar   rc   )Ú	threadingr   r   r   Úqueuer   r   rN   Úofflineimap.uir   r	   r   r   r4   r@   rB   r^   ra   rc   r1   r   r   ú<module>rk      s9  ðð$ 5Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø Ð Ð Ð Ð Ð Ð Ð Ø Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &à€ðð ð ðð ð ð ð ñ ô ð ðD �‘”€ð(ð (ð (ðV5%ð 5%ð 5%ð 5%ð 5%�vñ 5%ô 5%ð 5%ðx Ð ð	Jð 	Jð 	JðAð Að Að Að AÐ,ñ Aô Að Að Að Ar   