§
    dŠtjo*  ã                   ó¼   — d dl Z d dlZd dlZd dlZddlmZmZ ddlm	Z	 ddl
mZ dgZ ej        ¦   «         Zd adadad„ Z	 	 	 	 	 	 	 	 	 	 dd„Z G d„ de¦  «        ZdS )é    Né   )ÚProcessPoolExecutorÚEXTRA_QUEUED_CALLS)Ú	cpu_count)Úget_contextÚget_reusable_executorc                  ój   — t           5  t          } t          dz  a| cddd¦  «         S # 1 swxY w Y   dS )z¯Ensure that each successive executor instance has a unique, monotonic id.

    The purpose of this monotonic id is to help debug and test automated
    instance creation.
    r   N)Ú_executor_lockÚ_next_executor_id)Úexecutor_ids    úe/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/joblib/externals/loky/reusable_executor.pyÚ_get_next_executor_idr      s�   € õ 
ð ð Ý'ˆÝ˜QÑÐØðð ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ð s   ˆ(¨,¯,é
   FÚauto© c
                 óT   — t                                | |||||||||	¬¦
  «
        \  }
}|
S )a¬  Return the current ReusableExectutor instance.

    Start a new instance if it has not been started already or if the previous
    instance was left in a broken state.

    If the previous instance does not have the requested number of workers, the
    executor is dynamically resized to adjust the number of workers prior to
    returning.

    Reusing a singleton instance spares the overhead of starting new worker
    processes and importing common python packages each time.

    ``max_workers`` controls the maximum number of tasks that can be running in
    parallel in worker processes. By default this is set to the number of
    CPUs on the host.

    Setting ``timeout`` (in seconds) makes idle workers automatically shutdown
    so as to release system resources. New workers are respawn upon submission
    of new tasks so that ``max_workers`` are available to accept the newly
    submitted tasks. Setting ``timeout`` to around 100 times the time required
    to spawn new processes and import packages in them (on the order of 100ms)
    ensures that the overhead of spawning workers is negligible.

    Setting ``kill_workers=True`` makes it possible to forcibly interrupt
    previously spawned jobs to get a new instance of the reusable executor
    with new constructor argument values.

    The ``job_reducers`` and ``result_reducers`` are used to customize the
    pickling of tasks and results send to the executor.

    When provided, the ``initializer`` is run first in newly spawned
    processes with argument ``initargs``.

    The environment variable in the child process are a copy of the values in
    the main process. One can provide a dict ``{ENV: VAL}`` where ``ENV`` and
    ``VAL`` are string literals to overwrite the environment variable ``ENV``
    in the child processes to value ``VAL``. The environment variables are set
    in the children before any module is loaded. This only works with the
    ``loky`` context.
    )
Úmax_workersÚcontextÚtimeoutÚkill_workersÚreuseÚjob_reducersÚresult_reducersÚinitializerÚinitargsÚenv)Ú_ReusablePoolExecutorr   )r   r   r   r   r   r   r   r   r   r   Ú	_executorÚ_s               r   r   r   %   sI   € õh )×>Ò>ØØØØ!ØØ!Ø'ØØØð ?ñ ô �L€Iˆqð Ðó    c                   ó~   ‡ — e Zd Z	 	 	 	 	 	 	 	 	 dˆ fd„	Ze	 	 	 	 	 	 	 	 	 	 dd„¦   «         Zˆ fd	„Zd
„ Zd„ Zˆ fd„Z	ˆ xZ
S )r   Nr   r   c           
      óv   •— t          ¦   «                              |||||||	|
¬¦  «         || _        || _        d S )N)r   r   r   r   r   r   r   r   )ÚsuperÚ__init__r   Ú_submit_resize_lock)ÚselfÚsubmit_resize_lockr   r   r   r   r   r   r   r   r   Ú	__class__s              €r   r$   z_ReusablePoolExecutor.__init__i   sV   ø€ õ 	‰Œ×ÒØ#ØØØ%Ø+Ø#ØØð 	ñ 		
ô 		
ð 		
ð 'ˆÔØ#5ˆÔ Ð Ð r    r   Fr   c           
      ó&  — t           5  t          }|€|du r
|�|j        }n(t          ¦   «         }n|dk    rt	          d|› d�¦  «        ‚t          |t          ¦  «        rt          |¦  «        }|�'|                     ¦   «         dk    rt	          d¦  «        ‚t          ||||||	|
¬¦  «        }|€Jd}t          j                             d	|› d�¦  «         t          ¦   «         }|a | t           f||d
œ|¤Žxa}�n|dk    r|t          k    }|j        j        s|j        j        s|r|j        |k     rŒ|j        j        rd}n|j        j        rd}n|j        |k     rd}nd}t          j                             d|› d|› d�¦  «         |                     d|¬¦  «         d xax}a | j        dd|i|¤Žcd d d ¦  «         S t          j                             d|j        › d�¦  «         d}|                     |¦  «         d d d ¦  «         n# 1 swxY w Y   ||fS )NTr   z(max_workers must be greater than 0, got ú.Úforkz4Cannot use reusable executor with the 'fork' context)r   r   r   r   r   r   r   Fz#Create a executor with max_workers=)r   r   r   ÚbrokenÚshutdownzqueue size is too smallzarguments have changedz)Creating a new executor with max_workers=z, as the previous instance cannot be reused (z).)Úwaitr   r   z+Reusing existing executor with max_workers=r   )r
   r   Ú_max_workersr   Ú
ValueErrorÚ
isinstanceÚstrr   Úget_start_methodÚdictÚmpÚutilÚdebugr   Ú_executor_kwargsÚ_flagsr,   r-   Ú
queue_sizer   Ú_resize)Úclsr   r   r   r   r   r   r   r   r   r   ÚexecutorÚkwargsÚ	is_reusedr   Úreasons                   r   r   z+_ReusablePoolExecutor.get_reusable_executorƒ   ss  € õ ð O	2ð O	2å ˆHàÐ"Ø˜D�=�= XÐ%9Ø"*Ô"7�K�Kå"+¡+¤+�K�KØ Ò!Ð!Ý ØM¸{ÐMÐMÐMñô ð õ ˜'¥3Ñ'Ô'ð /Ý% gÑ.Ô.�ØÐ" w×'?Ò'?Ñ'AÔ'AÀVÒ'KÐ'KÝ ØJñô ð õ ØØØ)Ø /Ø'Ø!Øðñ ô ˆFð ÐØ!�	Ý”—’ØH¸+ÐHÐHÐHñô ð õ 4Ñ5Ô5�Ø#)Ð Ø'* sÝ"ð(à +Ø +ð(ð (ð ð	(ð (ð �	˜H™Hð ˜F’?�?Ø"Õ&6Ò6�Eà”OÔ*ð!2à”Ô/ð!2ð !ð!2ð  Ô*¨[Ò8Ð8à”Ô-ð 	:Ø!)˜˜Ø!œÔ1ð :Ø!+˜˜Ø!Ô,¨{Ò:Ð:ð ";˜˜à!9˜Ý”G—M’Mð.Ø&ð.ð .à#)ð.ð .ð .ñô ð ð
 ×%Ò%¨4¸lÐ%ÑKÔKÐKØ>BÐB�IÐB Ð+;à4˜3Ô4ð ð Ø$/ðØ39ðð ðMO	2ð O	2ð O	2ð O	2ñ O	2ô O	2ð O	2ð O	2õT ”G—M’Mð@Ø'/Ô'<ð@ð @ð @ñô ð ð !%�IØ×$Ò$ [Ñ1Ô1Ð1ð_O	2ð O	2ð O	2ñ O	2ô O	2ð O	2ð O	2ð O	2ð O	2ð O	2ð O	2øøøð O	2ð O	2ð O	2ð O	2ðb ˜Ð"Ð"s   ˆF$HÆ9?HÈHÈHc                 ó€   •— | j         5   t          ¦   «         j        |g|¢R i |¤Žcd d d ¦  «         S # 1 swxY w Y   d S ©N)r%   r#   Úsubmit)r&   ÚfnÚargsr>   r(   s       €r   rC   z_ReusablePoolExecutor.submitä   s“   ø€ ØÔ%ð 	7ð 	7Ø!•5‘7”7”> "Ð6 tÐ6Ð6Ð6¨vÐ6Ð6ð	7ð 	7ð 	7ð 	7ñ 	7ô 	7ð 	7ð 	7ð 	7ð 	7ð 	7ð 	7øøøð 	7ð 	7ð 	7ð 	7ð 	7ð 	7s   ‰3³7º7c                 óØ  — | j         5  |€t          d¦  «        ‚|| j        k    r	 d d d ¦  «         d S | j        €|| _        	 d d d ¦  «         d S |                      ¦   «          | j        5  t          | j                             ¦   «         ¦  «        }t          d„ |D ¦   «         ¦  «        }|| _        t          ||¦  «        D ]}| j                             d ¦  «         Œ	 d d d ¦  «         n# 1 swxY w Y   t          | j        ¦  «        |k    rD| j        j        s8t!          j        d¦  «         t          | j        ¦  «        |k    r| j        j        ¯8|                      ¦   «          t          | j                             ¦   «         ¦  «        }t'          d„ |D ¦   «         ¦  «        s-t!          j        d¦  «         t'          d„ |D ¦   «         ¦  «        ¯-d d d ¦  «         d S # 1 swxY w Y   d S )Nz&Trying to resize with max_workers=Nonec              3   ó>   K  — | ]}|                      ¦   «         V — Œd S rB   ©Úis_alive©Ú.0Úps     r   ú	<genexpr>z0_ReusablePoolExecutor._resize.<locals>.<genexpr>ý   s*   è è € Ð'HÐ'H¸¨¯
ª
©¬Ð'HÐ'HÐ'HÐ'HÐ'HÐ'Hr    çü©ñÒMbP?c              3   ó>   K  — | ]}|                      ¦   «         V — Œd S rB   rH   rJ   s     r   rM   z0_ReusablePoolExecutor._resize.<locals>.<genexpr>  s*   è è € Ð:Ð:¨1˜!Ÿ*š*™,œ,Ð:Ð:Ð:Ð:Ð:Ð:r    )r%   r0   r/   Ú_executor_manager_threadÚ_wait_job_completionÚ_processes_management_lockÚlistÚ
_processesÚvaluesÚsumÚrangeÚ_call_queueÚputÚlenr9   r,   ÚtimeÚsleepÚ_adjust_process_countÚall)r&   r   Ú	processesÚnb_children_aliver   s        r   r;   z_ReusablePoolExecutor._resizeè   s»  € ØÔ%ð  	!ð  	!ØÐ"Ý Ð!IÑJÔJÐJØ Ô 1Ò1Ð1Øð	 	!ð  	!ð  	!ñ  	!ô  	!ð  	!ð  	!ð  	!ð Ô,Ð4ð %0�Ô!Øð 	!ð  	!ð  	!ñ  	!ô  	!ð  	!ð  	!ð  	!ð ×%Ò%Ñ'Ô'Ð'ð
 Ô0ð /ð /Ý  ¤×!7Ò!7Ñ!9Ô!9Ñ:Ô:�	Ý$'Ð'HÐ'H¸iÐ'HÑ'HÔ'HÑ$HÔ$HÐ!Ø$/�Ô!Ý˜{Ð,=Ñ>Ô>ð /ð /�AØÔ$×(Ò(¨Ñ.Ô.Ð.Ð.ð/ð	/ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /õ �D”OÑ$Ô$ {Ò2Ð2¸4¼;Ô;MÐ2å”
˜4Ñ Ô Ð õ �D”OÑ$Ô$ {Ò2Ð2¸4¼;Ô;MÐ2ð ×&Ò&Ñ(Ô(Ð(Ý˜Tœ_×3Ò3Ñ5Ô5Ñ6Ô6ˆIÝÐ:Ð:°	Ð:Ñ:Ô:Ñ:Ô:ð !Ý”
˜4Ñ Ô Ð õ Ð:Ð:°	Ð:Ñ:Ô:Ñ:Ô:ð !ð? 	!ð  	!ð  	!ñ  	!ô  	!ð  	!ð  	!ð  	!ð  	!ð  	!ð  	!ð  	!øøøð  	!ð  	!ð  	!ð  	!ð  	!ð  	!sB   ˆG³GÁGÁ*A4C+ÃGÃ+C/	Ã/GÃ2C/	Ã3CGÇG#Ç&G#c                 óà   — | j         rBt          j        dt          ¦  «         t          j                             d| j        › d�¦  «         | j         rt          j	        d¦  «         | j         °dS dS )z8Wait for the cache to be empty before resizing the pool.z\Trying to resize an executor with running jobs: waiting for jobs completion before resizing.z	Executor z, waiting for jobs completion before resizingrN   N)
Ú_pending_work_itemsÚwarningsÚwarnÚUserWarningr5   r6   r7   r   r[   r\   )r&   s    r   rQ   z*_ReusablePoolExecutor._wait_job_completion  sœ   € ð Ô#ð 		ÝŒMð?åñô ð õ
 ŒG�MŠMð"˜DÔ,ð "ð "ð "ñô ð ð
 Ô&ð 	ÝŒJ�tÑÔÐð Ô&ð 	ð 	ð 	ð 	ð 	r    c                 óÀ   •— t          t          ¦   «         | j        ¦  «        }d|z  t          z   | _        t          ¦   «                              ||| j        ¬¦  «         d S )Né   )r:   )Úmaxr   r/   r   r:   r#   Ú_setup_queues)r&   r   r   Úmin_queue_sizer(   s       €r   ri   z#_ReusablePoolExecutor._setup_queues  sa   ø€ õ �Y™[œ[¨$Ô*;Ñ<Ô<ˆØ˜nÑ,Õ/AÑAˆŒÝ‰Œ×ÒØ˜/°d´oð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r    )	NNNr   NNNr   N©
NNr   Fr   NNNr   N)Ú__name__Ú
__module__Ú__qualname__r$   Úclassmethodr   rC   r;   rQ   ri   Ú__classcell__)r(   s   @r   r   r   h   sð   ø€ € € € € ð ØØØØØØØØð6ð 6ð 6ð 6ð 6ð 6ð4 ð ØØØØØØØØØð^#ð ^#ð ^#ñ „[ð^#ð@7ð 7ð 7ð 7ð 7ð!!ð !!ð !!ðFð ð ð"

ð 

ð 

ð 

ð 

ð 

ð 

ð 

ð 

r    r   rk   )r[   rc   Ú	threadingÚmultiprocessingr5   Úprocess_executorr   r   Úbackend.contextr   Úbackendr   Ú__all__ÚRLockr
   r   r   r8   r   r   r   r   r    r   ú<module>rx      s  ðð €€€Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð à EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ &Ð &Ð &Ð &Ð &Ð &Ø  Ð  Ð  Ð  Ð  Ð  à"Ð
#€ð !�”Ñ"Ô"€ØÐ Ø€	ØÐ ð
ð 
ð 
ð ØØØØ
ØØØØØð@ð @ð @ð @ðF~
ð ~
ð ~
ð ~
ð ~
Ð/ñ ~
ô ~
ð ~
ð ~
ð ~
r    