Ë
    ãß²j  ã                  ód   — d 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gZ G d„ de«      Zy)	u4  Shared daemon-thread ThreadPoolExecutor.

Stdlib workers are non-daemon AND registered in ``_threads_queues``, whose atexit
hook joins every worker even after ``shutdown(wait=False)`` â€” one wedged worker
(tool blocked on network I/O, hung provider, stuck subagent) blocks interpreter
exit forever. This variant spawns daemon workers and skips that registration.
Use it for best-effort/interruptible work that must never hold the process open;
NOT for work that must complete before exit (durable writes belong on foreground
threads with explicit bounded joins).
é    )ÚannotationsN)ÚThreadPoolExecutor)Ú_worker)Úcopy_contextÚDaemonThreadPoolExecutorc                  ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )r   zCThreadPoolExecutor variant whose workers do not block process exit.c               óN   •‡‡— t        «       Šˆˆfd„}t        ‰| �  |g|¢­i |¤ŽS )u”  Submit a callable, propagating the caller's contextvars. Stdlib only does
        this from 3.14; on 3.11-3.13 a bare worker starts with an EMPTY Context and
        drops profile secret scope / HERMES_HOME override â€” under the multiplexed
        gateway a credential read then fails closed with ``UnscopedSecretError``.
        Unconditional: on 3.14+ ``ctx.run`` re-applies the same context (no-op).c                 ó0   •—  ‰j                   ‰g| ¢­i |¤ŽS ©N)Úrun)Ú	call_argsÚcall_kwargsÚctxÚfns     €€ú6/home/ubuntu/.hermes/hermes-agent/tools/daemon_pool.pyÚ_run_with_contextz:DaemonThreadPoolExecutor.submit.<locals>._run_with_context"   s   ø€ Ø�3—7‘7˜2Ð9 	Ò9¨[Ñ9Ð9ó    )r   ÚsuperÚsubmit)Úselfr   ÚargsÚkwargsr   r   Ú	__class__s    `   @€r   r   zDaemonThreadPoolExecutor.submit   s+   ú€ ô ‹nˆõ	:ä‰w‰~Ð/ÐA°$ÒA¸&ÑAÐAr   c                ó(  — | j                   j                  d¬«      ry | j                  fd„}t        | j                  «      }|| j
                  k  rÂd| j                  xs | |fz  }t        j                  | |«      }t        | d«      r|| j                  «       | j                  f}n$|| j                  | j                  | j                  f}t        j                  |t        d|¬«      }|j!                  «        | j                  j#                  |«       y y )Nr   )Útimeoutc                ó&   — |j                  d «       y r   )Úput)Ú_Úqs     r   Ú
weakref_cbzADaemonThreadPoolExecutor._adjust_thread_count.<locals>.weakref_cb,   s   € Ø�E‰E�$�Kr   z%s_%dÚ_create_worker_contextT)ÚnameÚtargetÚdaemonr   )Ú_idle_semaphoreÚacquireÚ_work_queueÚlenÚ_threadsÚ_max_workersÚ_thread_name_prefixÚweakrefÚrefÚhasattrr!   Ú_initializerÚ	_initargsÚ	threadingÚThreadr   ÚstartÚadd)r   r    Únum_threadsÚthread_nameÚexecutor_refÚworker_argsÚts          r   Ú_adjust_thread_countz-DaemonThreadPoolExecutor._adjust_thread_count&   s  € ð ×Ñ×'Ñ'°Ð'Ô2Øà ×,Ñ,ó 	ä˜$Ÿ-™-Ó(ˆØ˜×*Ñ*Ò*Ø! T×%=Ñ%=Ò%EÀÀ{Ð$SÑSˆKÜ"Ÿ;™; t¨ZÓ8ˆLÜ�tÐ5Ô6ð !Ø×/Ñ/Ó1Ø×$Ñ$ð‘ð !Ø×$Ñ$Ø×%Ñ%Ø—N‘Nð	�ô × Ñ Ø ¬¸Ø ôˆAð �G‰GŒIØ�M‰M×Ñ˜aÕ ð3 +r   )ÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r:   Ú__classcell__)r   s   @r   r   r      s   ø„ ÙMô
B÷"!r   )r@   Ú
__future__r   r1   r,   Úconcurrent.futuresr   Úconcurrent.futures.threadr   Úcontextvarsr   Ú__all__r   © r   r   ú<module>rH      s3   ðñ	õ #ã Û Ý 1Ý -Ý $à%Ð
&€ô1!Ð1õ 1!r   