§
    Þa{cÿx  ã                   ót  — d dl mZ d dl mZ d dl mZ d dlZd dlZ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 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 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! d dlm"Z" d dlm#Z# ddgZ$d„ Z%efd„Z&efd„Z' G d„ de¦  «        Z( G d„ de¦  «        Z) G d„ de*¦  «        Z+ e+¦   «         Z+ G d „ de*¦  «        Z,	 d dl-Z.e$ /                    d!¦  «         d d"l0m1Z2 d d#l3m4Z4 d d$l-m5Z6 d%„ Z7d&„ Z8 G d'„ d(e*¦  «        Z9 G d)„ d!e.j:        j;        ¦  «        Z;dS # e<$ r Y dS w xY w)*é    )Úabsolute_import)Údivision)Úprint_functionN)Úgreenlet)Úmonkey)Úinteger_types)ÚAsyncResult)ÚInvalidThreadUseError)ÚGreenlet)Úget_hub_if_exists)Ú_get_hub_noargs)Ú
getcurrent)Úsleep)Ú	Semaphore)ÚGroupMappingMixin)Úclear_stack_frames)ÚQueue)ÚEmptyTimeout)Ústart_new_thread)Úget_thread_identÚ
ThreadPoolÚThreadResultc                 óR   — | €dS d| j         j        t          | ¦  «        | j        fz  S )Nz	<missing>z<%s at 0x%x thread_ident=0x%x>)Ú	__class__Ú__name__ÚidÚthread_ident)Úhubs    ú3/usr/lib/python3/dist-packages/gevent/threadpool.pyÚ_format_hubr    %   s3   € Ø
€{Øˆ{Ø+ØŒÔ¥ 3¡¤¨Ô)9ð/ñ ð ó    c                 ó<   — d| j         v r| j         d         j        S d S ©NÚ	threading)ÚmodulesÚ_profile_hook©Ú_syss    r   Ú_get_thread_profiler)   -   s'   € Ø�d”lÐ"Ð"ØŒ|˜KÔ(Ô6Ð6ð #Ð"r!   c                 ó<   — d| j         v r| j         d         j        S d S r#   )r%   Ú_trace_hookr'   s    r   Ú_get_thread_tracer,   2   s'   € Ø�d”lÐ"Ð"ØŒ|˜KÔ(Ô4Ð4ð #Ð"r!   c                   ó¬   — e Zd ZdZdZej        Z ee	¦  «        Z
dZdZdZdZd„ Zeefd„Zd„ Zed„ ¦   «         Zeeefd	„Zefd
„Zd„ Zd„ Zd„ Zefd„ZdS )Ú_WorkerGreenletTr   Néÿÿÿÿc                 óÐ  — t          j        | ¦  «         |j        | _        t	          j        d¦  «        rt	          j        dd¦  «        }nt          j        }|| _	        |j
        | _        | j                             ¦   «         | _        |j        | _        |j        | _        |                     | ¦  «         	 t#          | j        d¦  «         d S #  |                      | ¦  «         ‚ xY w)NÚsysÚstderr© )ÚRawGreenletÚ__init__r   Ú_hubr   Úis_module_patchedÚget_originalr1   r2   Ú_stderrÚ
task_queueÚ_task_queueÚallocate_cookieÚ_task_queue_cookieÚ_unregister_workerÚ_idle_task_timeoutÚ_register_workerr   Ú_begin)ÚselfÚ
threadpoolr2   s      r   r5   z_WorkerGreenlet.__init__P   sà   € õ 	Ô˜TÑ"Ô"Ð"à”NˆŒ	õ Ô# EÑ*Ô*ð 	 ÝÔ(¨°Ñ9Ô9ˆFˆFå”ZˆFØˆŒð &Ô0ˆÔØ"&Ô"2×"BÒ"BÑ"DÔ"DˆÔØ",Ô"?ˆÔØ",Ô"?ˆÔà×#Ò# DÑ)Ô)Ð)ð	Ý˜Tœ[¨"Ñ-Ô-Ð-Ð-Ð-øð	Ø×#Ò# DÑ)Ô)Ð)Øøøøs   Â6C ÃC%c                 ó”   —  |¦   «         | _          |¦   «         | _        d| j         _        	 |                      ¦   «          d S #  Y d S xY w©NT)ÚparentÚ_thread_identÚgreenlet_tree_is_ignoredÚswitch)rB   Ú_get_cÚ_get_tis      r   rA   z_WorkerGreenlet._begino   sQ   € ð
 �f‘h”hˆŒØ$˜W™YœYˆÔà/3ˆŒÔ,ð	Ø�KŠK‰MŒMˆMˆMˆMøð	ð ˆDˆDøøøs   ¬A ÁAc                 ó–   — |                       ¦   «         }|�2d|_        |� |j        �|j                             ¦   «          || _        d S d S )NzThreadPool Worker Hub)Ú_get_hub_if_existsÚnameÚperiodic_monitoring_threadÚ ignore_current_greenlet_blockingÚ_hub_of_worker)rB   r   s     r   Ú__fixup_hub_before_blockz(_WorkerGreenlet.__fixup_hub_before_block‚   sX   € Ø×%Ò%Ñ'Ô'ˆØˆ?Ø.ˆCŒHð
 ˆ 3Ô#AÐ#MØÔ.×OÒOÑQÔQÐQØ"%ˆDÔÐÐð ˆ?r!   c                 ó”   — | �E| j         }| j        }|j        }|j        }|j        }t          d|||fz  |¬¦  «         | j        } | ­Cd S d S )Nz  File "%s", line %d, in %s©Úfile)Útb_frameÚ	tb_linenoÚf_codeÚco_filenameÚco_nameÚprintÚtb_next)Útbr2   ÚfÚlinenoÚcoÚfilenamerN   s          r   Ú
__print_tbz_WorkerGreenlet.__print_tbŽ   sk   € ð
 ˆnØ”ˆAØ”\ˆFØ”ˆBØ”~ˆHØ”:ˆDÝÐ/°8¸VÀTÐ2JÑJØðñ ô ð à”ˆBð ˆnˆnˆnˆnˆnr!   c                 óz   — |                       |¦   «         ¦  «         |                      |¦   «         ¦  «         d S ©N©Ú
setprofileÚsettrace)rB   ÚfuncÚargsÚkwargsÚthread_resultr(   r)   r,   s           r   Ú_before_run_taskz _WorkerGreenlet._before_run_task�   sB   € ð
 	�ŠÐ+Ð+Ñ-Ô-Ñ.Ô.Ð.Ø�ŠÐ'Ð'Ñ)Ô)Ñ*Ô*Ð*Ð*Ð*r!   c                 óZ   — |                      d ¦  «         |                     d ¦  «         d S rd   re   )rB   rh   ri   rj   rk   r(   s         r   Ú_after_run_taskz_WorkerGreenlet._after_run_task¥   s,   € à�Š˜ÑÔÐØ�Š�dÑÔÐÐÐr!   c                 óL  — |                       ||||¦  «         	 |                      ||i |¤Ž¦  «         n1#  |                     | |f|                      ¦   «         ¦  «         Y nxY w|                      ||||¦  «         ~~~~d S # |                      ||||¦  «         ~~~~w xY wrd   )rl   ÚsetÚhandle_errorÚ	_exc_inforn   )rB   rh   ri   rj   rk   s        r   Ú
__run_taskz_WorkerGreenlet.__run_taskª   sÔ   € Ø×Ò˜d D¨&°-Ñ@Ô@Ð@ð	2Ø×Ò˜d˜d DÐ3¨FÐ3Ð3Ñ4Ô4Ð4Ð4øð	GØ×&Ò&¨¨d |°T·^²^Ñ5EÔ5EÑFÔFÐFÐFÐFøøøà× Ò   t¨V°]ÑCÔCÐCØ�d˜F M M Møð × Ò   t¨V°]ÑCÔCÐCØ�d˜F MÐ1Ð1Ð1Ð1s   š6 µB ¶,A$Á"B ÂB#c                 ó  — d }t           j        }| j        }| j        j        }| j        }| j        }| j        j        }| j        }	 	  |¦   «          	  |||¦  «        }n8# t          $ r+ Y |  
                    |                      ¦   «         ¦  «         d S w xY w	 |€M	 t          |t          ¦  «        sd n|} |¦   «          |  
                    |                      ¦   «         ¦  «         d S  ||Ž  n#  t          |¦  «        }‚ xY w	 t          |t          ¦  «        sd n|} |¦   «          n(# t          |t          ¦  «        sd n|} |¦   «          w xY w�Œ
# t          $ rO}	t!          d|›d|	›�| j        ¬¦  «         |                       |¦   «         d         | j        ¦  «         Y d }	~	nd }	~	ww xY w	 |  
                    |                      ¦   «         ¦  «         d S # |  
                    |                      ¦   «         ¦  «         w xY w)Né   z"Failed to run worker thread. Task=z Exception=rT   r/   )r1   Úexc_infoÚ'_WorkerGreenlet__fixup_hub_before_blockr;   Úgetr=   Ú_WorkerGreenlet__run_taskÚ	task_doner?   r   ÚcleanuprM   Ú
isinstanceÚstrÚreprÚ	Exceptionr[   r9   Ú_WorkerGreenlet__print_tb)
rB   Útaskrv   Úfixup_hub_before_blockÚtask_queue_getÚtask_queue_cookieÚrun_taskÚtask_queue_doneÚidle_task_timeoutÚes
             r   Úrunz_WorkerGreenlet.run´   su  € àˆÝ”<ˆØ!%Ô!>ÐØÔ)Ô-ˆØ Ô3ÐØ”?ˆØÔ*Ô4ˆØ Ô3Ðð!	4ð&Ø&Ð&Ñ(Ô(Ð(ðØ)˜>Ð*;Ð=NÑOÔO�D�DøÝ#ð ð ð ð
 ð, �LŠL˜×0Ò0Ñ2Ô2Ñ3Ô3Ð3Ð3Ð3ð7øøøð
&Ø�|Øõ (2°$½Ñ'<Ô'<ÐF˜4˜4À$�DØ#�OÑ%Ô%Ð%ð �LŠL˜×0Ò0Ñ2Ô2Ñ3Ô3Ð3Ð3Ð3ð# �H˜d�O�O�OøðÝ ™:œ:�DØøøøð $õ
 (2°$½Ñ'<Ô'<ÐF˜4˜4À$�DØ#�OÑ%Ô%Ð%Ð%øõ (2°$½Ñ'<Ô'<ÐF˜4˜4À$�DØ#�OÑ%Ô%Ð%Ð%øøøñ+&øõ, ð 	:ð 	:ð 	:ÝˆEà�D�D˜!˜!ðð ”\ð	#ñ #ô #ð #ð
 �OŠO˜H˜H™JœJ rœN¨D¬LÑ9Ô9Ð9Ð9Ð9Ð9Ð9Ð9øøøøð	:øøøð :ð �LŠL˜×0Ò0Ñ2Ô2Ñ3Ô3Ð3Ð3Ð3øˆD�LŠL˜×0Ò0Ñ2Ô2Ñ3Ô3Ð3Ð3øøøs…   ÁE ÁA ÁE Á
BÁ'E ÂBÂE ÂC+ Â#E Ã%C+ Ã*D% Ã+C=Ã=D% Ä$E Ä%%E
Å
E Å
F(ÅAF#ÆG Æ#F(Æ(G Ç)G>c                 óª   — | j         �2d | _         |                      | ¦  «         d„ | _        d | _        d | _        |�|                     d¦  «         d S d S )Nc                 ó   — d S rd   r3   )Ú_s    r   ú<lambda>z)_WorkerGreenlet.cleanup.<locals>.<lambda>å   s   € °€ r!   T)r6   r>   r;   r=   Údestroy)rB   Úhub_of_workers     r   r{   z_WorkerGreenlet.cleanupá   sg   € ØŒ9Ð ØˆDŒIØ×#Ò# DÑ)Ô)Ð)Ø&4 nˆDÔ#Ø#ˆDÔØ&*ˆDÔ#àÐ$Ø×!Ò! $Ñ'Ô'Ð'Ð'Ð'ð %Ð$r!   c                 óR   — dt          | ¦  «        | j         || j        ¦  «        fz  S )Nz><ThreadPoolWorker at 0x%x thread_ident=0x%x threadpool-hub=%s>)r   rG   r6   ©rB   r    s     r   Ú__repr__z_WorkerGreenlet.__repr__ì   s3   € ØOÝˆt‰HŒHØÔØˆK˜œ	Ñ"Ô"ðS
ñ 
ð 	
r!   )r   Ú
__module__Ú__qualname__Úgreenlet_tree_is_rootrG   r1   rv   rr   Ústaticmethodr   rM   rQ   r6   r=   r?   r5   r   r   rA   rw   r€   r)   r,   rl   rn   ry   r‰   r{   r    r’   r3   r!   r   r.   r.   7   s+  € € € € € ð !Ðà€MØ”€IØ%˜Ð&7Ñ8Ô8Ðð €Nà€Dð Ðð Ððð ð ð> 'Ð0@ð ð ð ð ð&
&ð 
&ð 
&ð ðð ñ „\ðð "Ø-@Ø+<ð+ð +ð +ð +ð GJð ð ð ð ð
2ð 2ð 2ð+4ð +4ð +4ðZ	(ð 	(ð 	(ð $/ð 
ð 
ð 
ð 
ð 
ð 
r!   r.   c                   óÐ   — e Zd ZdZdZeZdd„Zd„ Zd„ Zd„ Z	d	„ Z
 ee
e	d
¬¦  «        Zefd„Zd„ Zd„ Zd„ Z eeed¬¦  «        Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )r   a\
  
    A pool of native worker threads.

    This can be useful for CPU intensive functions, or those that
    otherwise will not cooperate with gevent. The best functions to execute
    in a thread pool are small functions with a single purpose; ideally they release
    the CPython GIL. Such functions are extension functions implemented in C.

    It implements the same operations as a :class:`gevent.pool.Pool`,
    but using threads instead of greenlets.

    .. note:: The method :meth:`apply_async` will always return a new
       greenlet, bypassing the threadpool entirely.

    Most users will not need to create instances of this class. Instead,
    use the threadpool already associated with gevent's hub::

        pool = gevent.get_hub().threadpool
        result = pool.spawn(lambda: "Some func").get()

    .. important:: It is only possible to use instances of this class from
       the thread running their hub. Typically that means from the thread that
       created them. Using the pattern shown above takes care of this.

       There is no gevent-provided way to have a single process-wide limit on the
       number of threads in various pools when doing that, however. The suggested
       way to use gevent and threadpools is to have a single gevent hub
       and its one threadpool (which is the default without doing any extra work).
       Only dispatch minimal blocking functions to the threadpool, functions that
       do not use the gevent hub.

    The `len` of instances of this class is the number of enqueued
    (unfinished) tasks.

    Just before a task starts running in a worker thread,
    the values of :func:`threading.setprofile` and :func:`threading.settrace`
    are consulted. Any values there are installed in that thread for the duration
    of the task (using :func:`sys.setprofile` and :func:`sys.settrace`, respectively).
    (Because worker threads are long-lived and outlast any given task, this arrangement
    lets the hook functions change between tasks, but does not let them see the
    bookkeeping done by the worker thread itself.)

    .. caution:: Instances of this class are only true if they have
       unfinished tasks.

    .. versionchanged:: 1.5a3
       The undocumented ``apply_e`` function, deprecated since 1.1,
       was removed.
    .. versionchanged:: 20.12.0
       Install the profile and trace functions in the worker thread while
       the worker thread is running the supplied task.
    .. versionchanged:: 22.08.0
       Add the option to let idle threads expire and be removed
       from the pool after *idle_task_timeout* seconds (-1 for no
       timeout)
    )	r   Ú_maxsizeÚmanagerÚpidÚfork_watcherÚ&_available_worker_threads_greenlet_semÚ_worker_greenletsr:   r?   Nr/   c                 ó|  — |€t          ¦   «         }|| _        t          j        ¦   «         | _        d | _        t          ¦   «         | _        d | _        || _	        t          ¦   «         | _        d| _        t          d|¦  «        | _        |                      |¦  «         |j                             d¬¦  «        | _        d S )Nr   ru   F)Úref)Úget_hubr   ÚosÚgetpidrš   r™   r   r:   r›   r?   rp   r�   r˜   r   rœ   Ú_set_maxsizeÚloopÚfork)rB   Úmaxsizer   r‡   s       r   r5   zThreadPool.__init__I  s    € Øˆ;Ý‘)”)ˆCØˆŒÝ”9‘;”;ˆŒØˆŒÝ™'œ'ˆŒØ ˆÔØ"3ˆÔå!$¡¤ˆÔØˆŒõ 7@ÀÀ3Ñ6GÔ6GˆÔ3Ø×Ò˜'Ñ"Ô"Ð"ØœHŸMšM¨e˜MÑ4Ô4ˆÔÐÐr!   c                 ó:   — | j                              |¦  «         d S rd   )r�   Úadd©rB   Úworkers     r   r@   zThreadPool._register_worker[  s   € ØÔ×"Ò" 6Ñ*Ô*Ð*Ð*Ð*r!   c                 ó:   — | j                              |¦  «         d S rd   )r�   Údiscardr©   s     r   r>   zThreadPool._unregister_worker^  s   € ØÔ×&Ò& vÑ.Ô.Ð.Ð.Ð.r!   c                 ó*  — t          |t          ¦  «        st          d|›�¦  «        ‚|dk     rt          d|›�¦  «        ‚|| j        z
  }| j        xj        |z  c_        || _        |                      ¦   «          | j                             ¦   «          d S )Nzmaxsize must be integer: r   zmaxsize must not be negative: )	r|   r   Ú	TypeErrorÚ
ValueErrorr˜   rœ   ÚcounterÚadjustÚ_start_notify)rB   r¦   Ú
differences      r   r£   zThreadPool._set_maxsizea  sš   € Ý˜'¥=Ñ1Ô1ð 	IÝ�)¸W¸WÐGÑHÔHÐHØ�QŠ;ˆ;Ý�*À7À7ÐMÑNÔNÐNØ˜tœ}Ñ,ˆ
ØÔ3Ð;Ô;¸zÑIÐ;Ô;ØˆŒØ�Š‰ŒˆàÔ3×AÒAÑCÔCÐCÐCÐCr!   c                 ó   — | j         S rd   )r˜   ©rB   s    r   Ú_get_maxsizezThreadPool._get_maxsizem  s
   € ØŒ}Ðr!   a9      The maximum allowed number of worker threads.

    This is also (approximately) a limit on the number of tasks that
    can be queued without blocking the waiting greenlet. If this many
    tasks are already running, then the next greenlet that submits a task
    will block waiting for a task to finish.
    )Údocc           	      ó�   — d| j         j        t          | ¦  «        t          | ¦  «        | j        | j         || j        ¦  «        fz  S )Nz/<%s at 0x%x tasks=%s size=%s maxsize=%s hub=%s>)r   r   r   ÚlenÚsizer¦   r   r‘   s     r   r’   zThreadPool.__repr__y  sF   € Ø@ØŒNÔ#Ýˆt‰HŒHÝ�‰IŒI�t”y $¤,ØˆK˜œÑ!Ô!ð	D
ñ 
ð 	
r!   c                 ó   — | j         j        S rd   )r:   Úunfinished_tasksrµ   s    r   Ú__len__zThreadPool.__len__�  s   € ð ŒÔ/Ð/r!   c                 ó*   — t          | j        ¦  «        S rd   )r¹   r�   rµ   s    r   Ú	_get_sizezThreadPool._get_size‡  s   € Ý�4Ô)Ñ*Ô*Ð*r!   c                 ó„  — |dk     rt          d|›�¦  «        ‚|| j        k    rt          d|›d| j        ›�¦  «        ‚| j        r| j                             ¦   «          t	          | j        ¦  «        |k     r,|                      ¦   «          t	          | j        ¦  «        |k     °,| j        j        j	        }t	          | j        ¦  «        |k    r´t	          | j        ¦  «        |z
  | j
        j        k    r?| j
                             d ¦  «         t	          | j        ¦  «        |z
  | j
        j        k    °?t          ¦   «         | j        u rn:t          |¦  «         t          |dz  d¦  «        }t	          | j        ¦  «        |k    °´| j        r!| j                             | j        ¦  «         d S | j                             ¦   «          d S )Nr   z%Size of the pool cannot be negative: z0Size of the pool cannot be bigger than maxsize: z > é   çš™™™™™©?)r¯   r˜   r™   Úkillr¹   r�   Ú_add_threadr   r¤   Úapprox_timer_resolutionr:   r¼   Úputr   r   Úminr›   ÚstartÚ_on_forkÚstop)rB   rº   Údelays      r   Ú	_set_sizezThreadPool._set_sizeŠ  s¹  € Ø�!Š8ˆ8Ý�*È$È$ÐQÑRÔRÐRØ�$”-ÒÐÝ�*ÐZ^ÐZ^ÐZ^Ð`dÔ`mÐ`mÐnÑoÔoÐoØŒ<ð 	 ØŒL×ÒÑÔÐÝ�$Ô(Ñ)Ô)¨DÒ0Ð0Ø×ÒÑÔÐõ �$Ô(Ñ)Ô)¨DÒ0Ð0à””Ô5ˆÝ�$Ô(Ñ)Ô)¨DÒ0Ð0Ý�dÔ,Ñ-Ô-°Ñ4°t´Ô7WÒWÐWØ”×#Ò# DÑ)Ô)Ð)õ �dÔ,Ñ-Ô-°Ñ4°t´Ô7WÒWÐWå‰|Œ|˜tœxÐ'Ð'ØÝ�%‰LŒLˆLÝ˜ ™	 3Ñ'Ô'ˆEõ �$Ô(Ñ)Ô)¨DÒ0Ð0ð Ô!ð 	%ØÔ×#Ò# D¤MÑ2Ô2Ð2Ð2Ð2àÔ×"Ò"Ñ$Ô$Ð$Ð$Ð$r!   a.      The number of running pooled worker threads.

    Setting this attribute will add or remove running
    worker threads, up to `maxsize`.

    Initially there are no pooled running worker threads, and
    threads are created on demand to satisfy concurrent
    requests up to `maxsize` threads.
    c                 óÒ  — t          j        ¦   «         }|| j        k    rÈt          t	          j        ¦   «         ¦  «        }t          | j        ¦  «        D ]^}|                     |j	        ¦  «        }t          |¦  «         |                     |j        ¦  «         |j                             ¦   «          Œ_| j                             ¦   «          |                      | j        ¦  «         d S d S rd   )r¡   r¢   rš   Údictr1   Ú_current_framesÚlistr�   rx   rG   r   r{   rQ   Ú__dict__Úclearr:   rÃ   r5   r˜   )rB   rš   Úthread_ident_to_framerª   Úframes        r   rÉ   zThreadPool._on_fork¬  sÖ   € õ
 Œi‰kŒkˆØ�$”(Š?ˆ?õ
 %)­Ô)<Ñ)>Ô)>Ñ$?Ô$?Ð!Ý˜tÔ5Ñ6Ô6ð (ð (�Ø-×1Ò1°&Ô2FÑGÔG�Ý" 5Ñ)Ô)Ð)Ø—’˜vÔ4Ñ5Ô5Ð5ð ”×%Ò%Ñ'Ô'Ð'Ð'ð ŒO× Ò Ñ"Ô"Ð"Ø�MŠM˜$œ-Ñ(Ô(Ð(Ð(Ð(ð) ˆ?r!   c                 óÌ   — t          d| j        j        j        ¦  «        }| j        j        dk    r4t          |¦  «         t          |dz  d¦  «        }| j        j        dk    °2dS dS )z6Waits until all outstanding tasks have been completed.gü©ñÒMb@?r   rÁ   rÂ   N)Úmaxr   r¤   rÅ   r:   r¼   r   rÇ   ©rB   rË   s     r   ÚjoinzThreadPool.joinÉ  sd   € å�F˜DœHœMÔAÑBÔBˆØŒoÔ.°Ò2Ð2Ý�%‰LŒLˆLÝ˜ ™	 3Ñ'Ô'ˆEð ŒoÔ.°Ò2Ð2Ð2Ð2Ð2Ð2r!   c                 óF   — d| _         | j                             ¦   «          d S )Nr   )rº   r›   Úcloserµ   s    r   rÃ   zThreadPool.killÐ  s$   € ØˆŒ	ØÔ×ÒÑ!Ô!Ð!Ð!Ð!r!   c                 óš  — t          | j        ¦  «        | j        k     ru| j        j        t          | j        ¦  «        k    rS|                      ¦   «          t          | j        ¦  «        | j        k     r"| j        j        t          | j        ¦  «        k    °St          | j        ¦  «        | j        z
  | j        j        k    rD| j                             d ¦  «         t          | j        ¦  «        | j        z
  | j        j        k    °D| j        r!| j                             | j	        ¦  «         d S | j        �| j         
                    ¦   «          d S d S rd   )r¹   r�   r˜   r:   r¼   rÄ   rÆ   r›   rÈ   rÉ   rÊ   rµ   s    r   Ú_adjust_stepzThreadPool._adjust_stepÔ  s0  € å�4Ô)Ñ*Ô*¨T¬]Ò:Ð:Ø”?Ô3µc¸$Ô:PÑ6QÔ6QÒQÐQØ×ÒÑÔÐõ �4Ô)Ñ*Ô*¨T¬]Ò:Ð:Ø”?Ô3µc¸$Ô:PÑ6QÔ6QÒQÐQõ �$Ô(Ñ)Ô)¨D¬MÑ9¸D¼OÔ<\Ò\Ð\ØŒO×Ò Ñ%Ô%Ð%õ �$Ô(Ñ)Ô)¨D¬MÑ9¸D¼OÔ<\Ò\Ð\àÔ!ð 	%ØÔ×#Ò# D¤MÑ2Ô2Ð2Ð2Ð2ØÔÐ*ØÔ×"Ò"Ñ$Ô$Ð$Ð$Ð$ð +Ð*r!   c                 óÒ   — | j         j        j        }	 |                      ¦   «          t	          | j        ¦  «        | j        k    rd S t          |¦  «         t          |dz  d¦  «        }ŒV)NTrÁ   rÂ   )	r   r¤   rÅ   rÜ   r¹   r�   r˜   r   rÇ   r×   s     r   Ú_adjust_waitzThreadPool._adjust_waitâ  se   € Ø””Ô5ˆð	(Ø×ÒÑÔÐÝ�4Ô)Ñ*Ô*¨d¬mÒ;Ð;Ø�Ý�%‰LŒLˆLÝ˜ ™	 3Ñ'Ô'ˆEð	(r!   c                 óº   — |                       ¦   «          | j        s=t          | j        ¦  «        | j        k    r"t          j        | j        ¦  «        | _        d S d S d S rd   )rÜ   r™   r¹   r�   r˜   r   ÚspawnrÞ   rµ   s    r   r±   zThreadPool.adjustë  s_   € Ø×ÒÑÔÐØŒ|ð 	=¥ DÔ$:Ñ ;Ô ;¸d¼mÒ KÐ Kõ $œ>¨$Ô*;Ñ<Ô<ˆDŒLˆLˆLð	=ð 	=Ð KÐ Kr!   c                 ó0   — |                       | ¦  «         d S rd   )r.   rµ   s    r   rÄ   zThreadPool._add_threadò  s   € Ø×Ò˜TÑ"Ô"Ð"Ð"Ð"r!   c                 ó²  — | j         t          ¦   «         k    rt          ‚	 | j        }|                     ¦   «          || j        u rnŒ&t          ¦   «         }| j        }d}	 t          || j         |j        ¦  «        }| 	                    ||||f¦  «         |  
                    ¦   «          n0#  |�|                     ¦   «          |                     ¦   «          ‚ xY w|S )aý  
        Add a new task to the threadpool that will run ``func(*args,
        **kwargs)``.

        Waits until a slot is available. Creates a new native thread
        if necessary.

        This must only be called from the native thread that owns this
        object's hub. This is because creating the necessary data
        structures to communicate back to this thread isn't thread
        safe, so the hub must not be running something else. Also,
        ensuring the pool size stays correct only works within a
        single thread.

        :return: A :class:`gevent.event.AsyncResult`.
        :raises InvalidThreadUseError: If called from a different thread.

        .. versionchanged:: 1.5
           Document the thread-safety requirements.
        ru   N)r   r    r
   rœ   Úacquirer	   r:   r   ÚreleaserÆ   r±   Údestroy_in_main_thread)rB   rh   ri   rj   Ú	semaphoreÚresultr:   rk   s           r   rà   zThreadPool.spawnõ  së   € ð* Œ8•w‘y”yÒ Ð Ý'Ð'ð	ØÔCˆIØ×ÒÑÔÐØ˜DÔGÐGÐGð ð	õ ‘”ˆØ”_ˆ
ð
 ˆð	Ý(¨°´¸9Ô;LÑMÔMˆMØ�NŠN˜D $¨°Ð>Ñ?Ô?Ð?Ø�KŠK‰MŒMˆMˆMøð	ØÐ(Ø×4Ò4Ñ6Ô6Ð6Ø×ÒÑÔÐØøøøØˆs   ÁAB' Â'-Cc                 ó,   — t          ¦   «         | j        uS rd   )r    r   rµ   s    r   Ú_apply_immediatelyzThreadPool._apply_immediately*  s   € õ ‰yŒy ¤Ð(Ð(r!   c                 ó   —  ||¦  «         d S rd   r3   )rB   Úcallbackrç   s      r   Ú_apply_async_cb_spawnz ThreadPool._apply_async_cb_spawn2  s   € Øˆ�ÑÔÐÐÐr!   c                 ó   — dS rE   r3   rµ   s    r   Ú_apply_async_use_greenletz$ThreadPool._apply_async_use_greenlet5  s   € àˆtr!   )Nr/   )r   r“   r”   Ú__doc__Ú	__slots__r.   r5   r@   r>   r£   r¶   Úpropertyr¦   r    r’   r½   r¿   rÌ   rº   rÉ   rØ   rÃ   rÜ   rÞ   r±   rÄ   rà   ré   rì   rî   r3   r!   r   r   r   ô   s®  € € € € € ð7ð 7ðr€Ið2 &€Oð5ð 5ð 5ð 5ð$+ð +ð +ð/ð /ð /ð
Dð 
Dð 
Dðð ð ð ˆh�| \ð 8ð 	ñ 	ô 	€Gð $/ð 
ð 
ð 
ð 
ð0ð 0ð 0ð+ð +ð +ð%ð %ð %ð, ˆ8�I˜yð 	/ð 		ñ 		ô 		€Dð)ð )ð )ð:(ð (ð (ð"ð "ð "ð%ð %ð %ð(ð (ð (ð=ð =ð =ð#ð #ð #ð3ð 3ð 3ðj)ð )ð )ðð ð ðð ð ð ð r!   c                   ó,   — e Zd Zd„ ZexZZd„ Zd„ ZeZdS )Ú
_FakeAsyncc                 ó   — d S rd   r3   rµ   s    r   Úsendz_FakeAsync.send;  s   € Øˆr!   c                 ó   — dS )zfake out for 'receiver'Nr3   )rB   rç   s     r   Ú__call__z_FakeAsync.__call__?  s   € € € r!   c                 ó   — dS )NFr3   rµ   s    r   Ú__bool__z_FakeAsync.__bool__B  s   € Øˆur!   N)	r   r“   r”   rõ   rÚ   rÊ   r÷   rù   Ú__nonzero__r3   r!   r   ró   ró   9  sL   € € € € € ðð ð àÐ€EˆDð"ð "ð "ðð ð ð €K€K€Kr!   ró   c                   óP   — e Zd ZdZdZd„ Zed„ ¦   «         Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
S )r   a  
    A one-time event for cross-thread communication.

    Uses a hub's "async" watcher capability; it must be constructed and
    destroyed in the thread running the hub (because creating, starting, and
    destroying async watchers isn't guaranteed to be thread safe).
    )rv   Úasync_watcherÚ_call_when_readyÚvalueÚcontextr   Úreceiverc                 óÔ   — || _         || _        d | _        d | _        d| _        |j                             ¦   «         | _        || _        | j         	                    | j
        ¦  «         d S )Nr3   )r   r   rÿ   rþ   rv   r¤   Úasync_rü   rý   rÈ   Ú	_on_async)rB   r   r   Úcall_when_readys       r   r5   zThreadResult.__init__V  s`   € Ø ˆŒØˆŒØˆŒØˆŒ
ØˆŒØ œXŸ_š_Ñ.Ô.ˆÔØ /ˆÔØÔ× Ò  ¤Ñ0Ô0Ð0Ð0Ð0r!   c                 ó.   — | j         r| j         d         nd S )Nru   )rv   rµ   s    r   Ú	exceptionzThreadResult.exception`  s   € à#'¤=Ð:ˆtŒ}˜QÔÐ°dÐ:r!   c                 óZ  — | j         }t          | _         |                     ¦   «          |                     ¦   «          	 |                      ¦   «          | j        r | j        j        | j        g| j        ¢R Ž  d | _        t          | _         d | _        t          | _        |  	                    | ¦  «         t          | _	        d | _
        | j        r"| j        d         | j        d         d f| _        d S d S # t          | _	        d | _
        | j        r | j        d         | j        d         d f| _        w xY w)Nr   ru   )rü   ró   rÊ   rÚ   rý   rv   r   rq   rÿ   r   rþ   )rB   Úaws     r   r  zThreadResult._on_asyncd  s+  € ð ÔˆÝ'ˆÔà
�Š‰	Œ	ˆ	Ø
�Š‰
Œ
ˆ
ð
	KØ×!Ò!Ñ#Ô#Ð#ØŒ}ð DØ%�”Ô% d¤lÐC°T´]ÐCÐCÐCÐCØˆDŒLÝ!+ˆDÔØˆDŒHÝ$.ˆDÔ!à�MŠM˜$ÑÔÐå&ˆDŒMØˆDŒJØŒ}ð KØ!%¤¨qÔ!1°4´=ÀÔ3CÀTÐ J�”��ðKð Køõ 'ˆDŒMØˆDŒJØŒ}ð KØ!%¤¨qÔ!1°4´=ÀÔ3CÀTÐ J�”ÐJÐJÐJÐJs   ½A3C. Ã.<D*c                 óÎ   — | j                              ¦   «          | j                              ¦   «          t          | _         d| _        d| _        t          | _        t          | _        dS )zK
        This must only be called from the thread running the hub.
        N)rü   rÊ   rÚ   ró   rÿ   r   rý   r   rµ   s    r   rå   z#ThreadResult.destroy_in_main_thread€  sW   € ð 	Ô×ÒÑ!Ô!Ð!ØÔ× Ò Ñ"Ô"Ð"Ý'ˆÔàˆŒØˆŒÝ *ˆÔÝ"ˆŒˆˆr!   c                 óF   — || _         | j                             ¦   «          d S rd   )rþ   rü   rõ   )rB   rþ   s     r   rp   zThreadResult.set�  s$   € ØˆŒ
ØÔ×ÒÑ!Ô!Ð!Ð!Ð!r!   c                 óT   — || _         || _        | j                             ¦   «          d S rd   )rÿ   rv   rü   rõ   )rB   rÿ   rv   s      r   rq   zThreadResult.handle_error‘  s+   € ØˆŒØ ˆŒØÔ×ÒÑ!Ô!Ð!Ð!Ð!r!   c                 ó   — | j         d u S rd   )r  rµ   s    r   Ú
successfulzThreadResult.successful—  s   € ØŒ~ Ð%Ð%r!   N)r   r“   r”   rï   rð   r5   rñ   r  r  rå   rp   rq   r  r3   r!   r   r   r   I  s�   € € € € € ðð ð/€Ið1ð 1ð 1ð ð;ð ;ñ „Xð;ðKð Kð Kð8#ð #ð #ð"ð "ð "ð"ð "ð "ð&ð &ð &ð &ð &r!   ÚThreadPoolExecutor)ÚTimeout)ÚLazy)Ú_basec                 ó   ‡ ‡— ˆˆ fd„}|S )Nc                 ó‚   •— ~ 	  ‰‰¦  «         d S # t           $ r# ‰j                             ‰‰fd d d ¦  «         Y d S w xY wrd   )r   r   Úprint_exception©rŒ   ÚfnÚfuture_proxys    €€r   Úcbwrapz_ignore_error.<locals>.cbwrap§  sm   ø€ ØðWØ��<Ñ Ô Ð Ð Ð øÝð Wð Wð WàÔ ×0Ò0°"°lÐ1CÀTÈ4ÐQUÑVÔVÐVÐVÐVÐVðWøøøs   „ ‘)>½>r3   )r  r  r  s   `` r   Ú_ignore_errorr  ¦  s/   øø€ ð	Wð 	Wð 	Wð 	Wð 	Wð 	Wð ˆr!   c                 ó   ‡ ‡— ˆˆ fd„}|S )Nc                 ó   •—  ‰‰¦  «         d S rd   r3   r  s    €€r   r^   z_wrap.<locals>.f³  s   ø€ ØˆBˆ|ÑÔÐÐÐr!   r3   )r  r  r^   s   `` r   Ú_wrapr  ²  s'   øø€ ð	ð 	ð 	ð 	ð 	ð 	àˆr!   c                   óŠ   — e Zd Zd„ Zed„ ¦   «         Zed„ ¦   «         Zd„ Zed„ ¦   «         Z	d„ Z
dd„Zdd	„Zd
„ Zd„ Zd„ Zd„ ZdS )Ú_FutureProxyc                 ó   — || _         d S rd   )Úasyncresult)rB   r   s     r   r5   z_FutureProxy.__init__¸  s   € Ø*ˆDÔÐÐr!   c                 ó    — t          j        d¦  «        s|                      ¦   «         rdd l}|                     ¦   «         S t          d¦  «        ‚)Nr$   r   Ú
_condition)r   r7   Údoner$   Ú	ConditionÚAttributeError)rB   r$   s     r   r"  z_FutureProxy._condition½  sR   € åÔ'¨Ñ4Ô4ð -¸¿	º	¹¼ð -Ø Ð Ð Ð Ø ×*Ò*Ñ,Ô,Ð,õ ! Ñ.Ô.Ð.r!   c                 óD   — | j                              | j        ¦  «         g S rd   )r   ÚrawlinkÚ_FutureProxy__when_donerµ   s    r   Ú_waitersz_FutureProxy._waitersÇ  s!   € àÔ×$Ò$ TÔ%5Ñ6Ô6Ð6ØˆIr!   c                 ó®   — t          | d¦  «        }|D ]A}|                      ¦   «         r|                     | ¦  «         Œ,|                     | ¦  «         ŒBd S )Nr)  )Úgetattrr  Ú
add_resultÚadd_exception)rB   rŒ   ÚwaitersÚws       r   Ú__when_donez_FutureProxy.__when_doneÌ  sh   € õ ˜d JÑ/Ô/ˆGØð *ð *�Ø—?’?Ñ$Ô$ð *Ø—L’L Ñ&Ô&Ð&Ð&à—O’O DÑ)Ô)Ð)Ð)ð	*ð *r!   c                 óZ   — |                       ¦   «         rt          j        S t          j        S rd   )r#  ÚcfbÚFINISHEDÚRUNNINGrµ   s    r   Ú_statez_FutureProxy._stateÖ  s"   € à�yŠy‰{Œ{ð $Ý”|Ð#Ý”;Ðr!   c                 ó   — d S rd   r3   rµ   s    r   Úset_running_or_notify_cancelz)_FutureProxy.set_running_or_notify_cancelÜ  s	   € ð ˆFr!   Nc                 ó’   — 	 | j                              |¬¦  «        S # t          $ r t          j                             ¦   «         ‚w xY w©N)Útimeout)r   rç   ÚGTimeoutÚ
concurrentÚfuturesÚTimeoutError©rB   r:  s     r   rç   z_FutureProxy.resultá  sS   € ð8ØÔ'×.Ò.°wÐ.Ñ?Ô?Ð?øÝð 8ð 8ð 8õ !Ô(×5Ò5Ñ7Ô7Ð7ð8øøøs	   ‚ �)Ac                 óª   — 	 | j                              |¬¦  «         | j         j        S # t          $ r t          j                             ¦   «         ‚w xY wr9  )r   rx   r  r;  r<  r=  r>  r?  s     r   r  z_FutureProxy.exceptioné  s]   € ð8ØÔ ×$Ò$¨WÐ$Ñ5Ô5Ð5ØÔ'Ô1Ð1øÝð 8ð 8ð 8Ý Ô(×5Ò5Ñ7Ô7Ð7ð8øøøs	   ‚&) ©)Ac                 ó˜   — |                       ¦   «         r || ¦  «         dS | j                             t          | |¦  «        ¦  «         dS )z&Exceptions raised by *fn* are ignored.N)r#  r   r'  r  ©rB   r  s     r   Úadd_done_callbackz_FutureProxy.add_done_callbackð  sK   € à�yŠy‰{Œ{ð BØ��4‘”���àÔ ×(Ò(­°t¸RÑ)@Ô)@ÑAÔAÐAÐAÐAr!   c                 óV   — | j                              t          | |¦  «        ¦  «         d S rd   )r   r'  r  rB  s     r   r'  z_FutureProxy.rawlink÷  s'   € ØÔ×$Ò$¥U¨4°¡_¤_Ñ5Ô5Ð5Ð5Ð5r!   c                 ó*   — t          | j        ¦  «        S rd   )r}   r   rµ   s    r   Ú__str__z_FutureProxy.__str__ú  s   € Ý�tÔ'Ñ(Ô(Ð(r!   c                 ó,   — t          | j        |¦  «        S rd   )r+  r   )rB   rN   s     r   Ú__getattr__z_FutureProxy.__getattr__ý  s   € Ý˜4Ô+¨TÑ2Ô2Ð2r!   rd   )r   r“   r”   r5   r  r"  r)  r(  rñ   r5  r7  rç   r  rC  r'  rF  rH  r3   r!   r   r  r  ·  sù   € € € € € ð	+ð 	+ð 	+ð
 
ð	/ð 	/ñ 
Œð	/ð 
ð	ð 	ñ 
Œð	ð	*ð 	*ð 	*ð 
ð	ð 	ñ 
Œð	ð
	ð 	ð 	ð
	8ð 	8ð 	8ð 	8ð	8ð 	8ð 	8ð 	8ð	Bð 	Bð 	Bð	6ð 	6ð 	6ð	)ð 	)ð 	)ð	3ð 	3ð 	3ð 	3ð 	3r!   r  c                   ó>   ‡ — e Zd ZdZˆ fd„Zd„ Zdˆ fd„	ZeZd„ Zˆ xZ	S )r  a  
        A version of :class:`concurrent.futures.ThreadPoolExecutor` that
        always uses native threads, even when threading is monkey-patched.

        The ``Future`` objects returned from this object can be used
        with gevent waiting primitives like :func:`gevent.wait`.

        .. caution:: If threading is *not* monkey-patched, then the ``Future``
           objects returned by this object are not guaranteed to work with
           :func:`~concurrent.futures.as_completed` and :func:`~concurrent.futures.wait`.
           The individual blocking methods like :meth:`~concurrent.futures.Future.result`
           and :meth:`~concurrent.futures.Future.exception` will always work.

        .. versionadded:: 1.2a1
           This is a provisional API.
        c                 óz   •—  t          t          | ¦  «        j        |i |¤Ž t          | j        ¦  «        | _        dS )a.  
            Takes the same arguments as ``concurrent.futures.ThreadPoolExecuter``, which
            vary between Python versions.

            The first argument is always *max_workers*, the maximum number of
            threads to use. Most other arguments, while accepted, are ignored.
            N)Úsuperr  r5   r   Ú_max_workersÚ_threadpool)rB   ri   rj   r   s      €r   r5   zThreadPoolExecutor.__init__  sA   ø€ ð 5�EÕ$ dÑ+Ô+Ô4°dÐE¸fÐEÐEÐEÝ)¨$Ô*;Ñ<Ô<ˆDÔÐÐr!   c                 óº   — | j         5  | j        rt          d¦  «        ‚ | j        j        |g|¢R i |¤Ž}t          |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S )Nz*cannot schedule new futures after shutdown)Ú_shutdown_lockÚ	_shutdownÚRuntimeErrorrM  rà   r  )rB   r  ri   rj   Úfutures        r   ÚsubmitzThreadPoolExecutor.submit  s¹   € ØÔ$ð ,ð ,Ø”>ð UÝ&Ð'SÑTÔTÐTà/˜Ô)Ô/°ÐD°TÐDÐDÐD¸VÐDÐD�Ý# FÑ+Ô+ð,ð ,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,ð ,ð ,s   ˆ;AÁAÁATc                 óº   •—  t          t          | ¦  «        j        |fi |¤Ž t          | j        dd ¦  «        }|r| j                             ¦   «          d | _        d S )NrÃ   )rK  r  Úshutdownr+  rM  rÃ   )rB   Úwaitrj   rÃ   r   s       €r   rU  zThreadPoolExecutor.shutdown%  sh   ø€ à4�EÕ$ dÑ+Ô+Ô4°TÐDÐD¸VÐDÐDÐDå˜4Ô+¨V°TÑ:Ô:ˆDØð (ØÔ ×%Ò%Ñ'Ô'Ð'Ø#ˆDÔÐÐr!   c                 ó   — d S rd   r3   rµ   s    r   Ú_adjust_thread_countz'ThreadPoolExecutor._adjust_thread_count0  s	   € ð ˆDr!   )T)
r   r“   r”   rï   r5   rS  rU  rÃ   rX  Ú__classcell__)r   s   @r   r  r     s…   ø€ € € € € ð	ð 	ð"		=ð 		=ð 		=ð 		=ð 		=ð	,ð 	,ð 	,ð	$ð 	$ð 	$ð 	$ð 	$ð 	$ð ˆð	ð 	ð 	ð 	ð 	ð 	ð 	r!   )=Ú
__future__r   r   r   r¡   r1   r   r4   Úgeventr   Úgevent._compatr   Úgevent.eventr	   Úgevent.exceptionsr
   Úgevent.greenletr   Úgevent._hub_localr   Ú
gevent.hubr   r    r   r   Úgevent.lockr   Úgevent.poolr   Úgevent.utilr   Úgevent._threadingr   r   r   r   Ú__all__r    r)   r,   r.   r   Úobjectró   r   Úconcurrent.futuresr<  ÚappendÚgevent.timeoutr  r;  Úgevent._utilr  r  r2  r  r  r  r=  r  ÚImportErrorr3   r!   r   ú<module>rm     s¯  ðà &Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à 	€	€	€	Ø 
€
€
€
ð -Ð ,Ð ,Ð ,Ð ,Ð ,à Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø $Ð $Ð $Ð $Ð $Ð $Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø $Ð $Ð $Ð $Ð $Ð $à /Ð /Ð /Ð /Ð /Ð /Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø )Ð )Ð )Ð )Ð )Ð )Ø *Ð *Ð *Ð *Ð *Ð *à #Ð #Ð #Ð #Ð #Ð #Ø *Ð *Ð *Ð *Ð *Ð *Ø .Ð .Ð .Ð .Ð .Ð .Ø .Ð .Ð .Ð .Ð .Ð .ð Øð€ð
ð ð ð !ð 7ð 7ð 7ð 7ð
 ð 5ð 5ð 5ð 5ð
z
ð z
ð z
ð z
ð z
�kñ z
ô z
ð z
ðzCð Cð Cð Cð CÐ"ñ Cô Cð CðJ
ð ð ð ð �ñ ô ð ð ˆZ‰\Œ\€
ðO&ð O&ð O&ð O&ð O&�6ñ O&ô O&ð O&ðdXØÐÐÐð ‡N‚NÐ'Ñ(Ô(Ð(à2Ð2Ð2Ð2Ð2Ð2Ø!Ð!Ð!Ð!Ð!Ð!Ø/Ð/Ð/Ð/Ð/Ð/ð
ð 
ð 
ðð ð ð
G3ð G3ð G3ð G3ð G3�vñ G3ô G3ð G3ðR3ð 3ð 3ð 3ð 3˜ZÔ/ÔBñ 3ô 3ð 3ð 3ð 3øðG ð 	ð 	ð 	Ø€D€Dð	øøøs   ÃD. Ä.D7Ä6D7