ó
    Ð]jo*  ã                   óº   • S SK r S SKrS SKrS SKrSSKJrJr  SSKJ	r	  SSK
Jr  S/r\R                  " 5       rS qSqSqS r          SS jr " S	 S
\5      rg)é    Né   )ÚProcessPoolExecutorÚEXTRA_QUEUED_CALLS)Ú	cpu_count)Úget_contextÚget_reusable_executorc                  óf   • [            [        n [        S-  qU sSSS5        $ ! , (       d  f       g= f)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    Úd/home/mande/repo/quber/.venv/lib/python3.13/site-packages/joblib/externals/loky/reusable_executor.pyÚ_get_next_executor_idr      s$   € ö 
Ü'ˆÜ˜QÑÐØ÷ 
��ús   ‡"¢
0c
                 óB   • [         R                  U UUUUUUUUU	S9
u  p«U
$ )a4  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   %   sB   € ôh )×>Ñ>ØØØØ!ØØ!Ø'ØØØð ?ð �L€Ið Ðó    c                   óŠ   ^ • \ rS rSr         S	U 4S jjr\          S
S j5       rU 4S jrS rS r	U 4S jr
SrU =r$ )r   éh   c                 óF   >• [         TU ]  UUUUUUU	U
S9  XPl        Xl        g )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"   Ú_ReusablePoolExecutor.__init__i   s=   ø€ ô 	‰ÑØ#ØØØ%Ø+Ø#ØØð 	ñ 		
ð 'ÔØ#5Õ r   c                 óˆ  • [            [        nUc   USL a  Ub  UR                  nO [        5       nOUS::  a  [	        SU S35      e[        U[        5      (       a  [        U5      nUb  UR                  5       S:X  a  [	        S5      e[        UUUUUU	U
S9nUcE  Sn[        R                  R                  S	U S35        [        5       nUqU " [         4UUS
.UD6=qnGOFUS:X  a	  U[        :H  nUR                  R                   (       d2  UR                  R"                  (       d  U(       a  UR$                  U:  aª  UR                  R                   (       a  SnO3UR                  R"                  (       a  SnOUR$                  U:  a  SnOSn[        R                  R                  SU SU S35        UR#                  SUS9  S =q=nqU R&                  " SSU0UD6sS S S 5        $ [        R                  R                  SUR                   S35        SnUR)                  U5        S S S 5        X½4$ ! , (       d  f       WW4$ = f)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   ÚautoÚ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   Ú_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   Ú+_ReusablePoolExecutor.get_reusable_executorƒ   sn  € ö ä ˆHàÑ"Ø˜D’= XÑ%9Ø"*×"7Ñ"7‘Kä"+£+‘KØ Ó!Ü Ø>¸{¸mÈ1ÐMóð ô ˜'¤3×'Ñ'Ü% gÓ.�ØÑ" w×'?Ñ'?Ó'AÀVÓ'KÜ ØJóð ô ØØØ)Ø /Ø'Ø!ØñˆFð ÑØ!�	Ü—‘—‘Ø9¸+¸ÀaÐHôô 4Ó5�Ø#)Ð Ù'*Ü"ð(à +Ø +ñ(ð ñ	(ð �	šHð ˜F“?Ø"Ô&6Ñ6�Eà—O‘O×*×*Ø—‘×/×/Þ Ø×*Ñ*¨[Ó8à—‘×-×-Ø!)™Ø!Ÿ™×1×1Ø!+™Ø!×,Ñ,¨{Ó:ð ";™à!9˜Ü—G‘G—M‘MØCØ&˜-ð (#Ø#) (¨"ð.ôð
 ×%Ñ%¨4¸lÐ%ÑKØ>BÐB�IÐB Ð+;à×4Ò4ñ Ø$/ðØ39ñ÷M ‰^ôT —G‘G—M‘Mð'Ø'/×'<Ñ'<Ð&=¸Qð@ôð !%�IØ×$Ñ$ [Ô1÷_ ðb Ð"Ð"÷c Œ^ðb ˜Ð"Ð"ús   ‡GH0Ç%A H0È0
Ic                 óz   >• U R                      [        TU ]  " U/UQ70 UD6sS S S 5        $ ! , (       d  f       g = f©N)r#   r!   Úsubmit)r$   ÚfnÚargsr?   r&   s       €r   rE   Ú_ReusablePoolExecutor.submitä   s.   ø€ Ø×%Ó%Ü‘7’> "Ð6 tÒ6¨vÑ6÷ &×%×%ús   Ž,¬
:c                 ó  • U R                      Uc  [        S5      eXR                  :X  a
   S S S 5        g U R                  c  Xl         S S S 5        g U R	                  5         U R
                     [        U R                  R                  5       5      n[        S U 5       5      nXl        [        X5       H  nU R                  R                  S 5        M      S S S 5        [        U R                  5      U:”  ag  U R                  R                  (       dL  [         R"                  " S5        [        U R                  5      U:”  a  U R                  R                  (       d  ML  U R%                  5         [        U R                  R                  5       5      n['        S U 5       5      (       d/  [         R"                  " S5        ['        S U 5       5      (       d  M/  S S S 5        g ! , (       d  f       GN= f! , (       d  f       g = f)Nz&Trying to resize with max_workers=Nonec              3   ó@   #   • U  H  oR                  5       v •  M     g 7frD   ©Úis_alive©Ú.0Úps     r   Ú	<genexpr>Ú0_ReusablePoolExecutor._resize.<locals>.<genexpr>ý   s   é € Ð'Hºi¸¯
©
¯¨ºiùó   ‚çü©ñÒMbP?c              3   ó@   #   • U  H  oR                  5       v •  M     g 7frD   rK   rM   s     r   rP   rQ     s   é € Ð:²	¨1Ÿ*™*Ÿ,˜,²	ùrR   )r#   r1   r0   Ú_executor_manager_threadÚ_wait_job_completionÚ_processes_management_lockÚlistÚ
_processesÚvaluesÚsumÚrangeÚ_call_queueÚputÚlenr:   r,   ÚtimeÚsleepÚ_adjust_process_countÚall)r$   r   Ú	processesÚnb_children_aliver   s        r   r<   Ú_ReusablePoolExecutor._resizeè   s€  € Ø×%Ó%ØÑ"Ü Ð!IÓJÐJØ× 1Ñ 1Ó1Ø÷	 &Ð%ð ×,Ñ,Ñ4ð %0Ô!Ø÷ &Ð%ð ×%Ñ%Ô'ð
 ×0Ó0Ü  §¡×!7Ñ!7Ó!9Ó:�	Ü$'Ñ'H¹iÓ'HÓ$HÐ!Ø$/Ô!Ü˜{Ö>�AØ×$Ñ$×(Ñ(¨Ö.ñ ?÷	 1ô �D—O‘OÓ$ {Ó2¸4¿;¹;×;M×;Mä—
’
˜4Ô ô �D—O‘OÓ$ {Ó2¸4¿;¹;×;M×;MÑ;Mð ×&Ñ&Ô(Ü˜TŸ_™_×3Ñ3Ó5Ó6ˆIÜÑ:±	Ó:×:Ñ:Ü—
’
˜4Ô ô Ñ:±	Ó:×:Ó:÷? &Ð%÷$ 1Ö0ú÷% &Õ%ús7   �G3µG3ÁG3Á.A)G!ÃBG3ÅA7G3Ç!
G0	Ç+G3Ç3
Hc                 ó,  • U R                   (       aH  [        R                  " S[        5        [        R
                  R                  SU R                   S35        U R                   (       a*  [        R                  " S5        U R                   (       a  M)  gg)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 resizingrS   N)
Ú_pending_work_itemsÚwarningsÚwarnÚUserWarningr6   r7   r8   r   r`   ra   )r$   s    r   rV   Ú*_ReusablePoolExecutor._wait_job_completion  sp   € ð ×#×#Ü�MŠMð?äôô
 �G‰G�M‰MØ˜D×,Ñ,Ð-ð ."ð "ôð
 ×&×&Ü�JŠJ�tÔð ×&×&Ó&r   c                 ó”   >• [        [        5       U R                  5      nSU-  [        -   U l        [
        TU ]  XU R                  S9  g )Né   )r;   )Úmaxr   r0   r   r;   r!   Ú_setup_queues)r$   r   r   Úmin_queue_sizer&   s       €r   rp   Ú#_ReusablePoolExecutor._setup_queues  sF   ø€ ô œY›[¨$×*;Ñ*;Ó<ˆØ˜nÑ,Ô/AÑAˆŒÜ‰ÑØ°d·o±oð 	ò 	
r   )r0   r#   r   r;   )	NNNr   NNNr/   N©
NNé
   Fr+   NNNr/   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r"   Úclassmethodr   rE   r<   rV   rp   Ú__static_attributes__Ú__classcell__)r&   s   @r   r   r   h   sv   ø† ð ØØØØØØØØ÷6ð4 ð ØØØØØØØØØó^#ó ð^#õ@7ò!!òF÷"

ó 

r   r   rs   )r`   ri   Ú	threadingÚmultiprocessingr6   Úprocess_executorr   r   Úbackend.contextr   Úbackendr   Ú__all__ÚRLockr
   r   r   r9   r   r   r   r/   r   r   Ú<module>rƒ      s~   ðó Û Û Û ç EÝ &Ý  à"Ð
#€ð —’Ó"€ØÐ Ø€	ØÐ ò
ð ØØØØ
ØØØØØô@ôF~
Ð/õ ~
r   