+
    iHàj×  ã                  óÈ   € R t ^ RIHt ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
HtHt ]P                  ! ]4      tRtRt ! R R4      t ! R	 R
4      t]! 4       tR R ltR# )uÓ  One process-wide timer thread for periodic maintenance callbacks.

Replaces the per-child ``while not stop.wait(interval): body()`` daemon
threads (delegate heartbeat, durable turn-lease refresher, turn-liveness
watchdog).  With ~130 in-process subagents those added 2-3 sleeping OS
threads per child.  This module keeps ONE daemon thread that only orders due
times; every due body runs on its own short-lived daemon worker.  A blocked
callback therefore cannot delay unrelated lease/liveness timers, while
steady-state thread use stays near zero (workers exist only while a body is
actually running, never one per scheduled handle).

Semantics match the loop they replace: the first call happens ``interval``
seconds after :func:`schedule`, and each following call ``interval`` seconds
after the previous body *returned* (drift-free wrt. body duration was never
a property of the old loops either).  A body that returns ``False`` stops
itself; a body that raises is logged at debug and rescheduled â€” one bad
callback must never kill the shared thread.  A handle never overlaps itself:
it is re-queued only once its in-flight run has returned.  A worker-start
failure never retires the handle: it is re-queued and logged at warning.
)Úannotations)Úcopy_contextN)ÚCallableÚOptionalzhermes-periodic-schedulerzhermes-periodic-callbackc                  óP   € ] tR t^&tRtR	tR R lt]R R l4       tR
R R llt	R	t
R# )ÚScheduledHandlez1Cancel token for one scheduled periodic callback.c               ó$   € V ^8„  d   QhRRRRRR/# )é   Ú	schedulerÚPeriodicSchedulerÚfnúCallable[[], object]ÚintervalÚfloat© )Úformats   "Ú=/home/ubuntu/.hermes/hermes-agent/agent/periodic_scheduler.pyÚ__annotate__ÚScheduledHandle.__annotate__+   s$   € ÷ 'ñ 'Ð"3ð 'Ð9Mð 'ÐY^ñ 'ó    c                	ód   € Wn         W n        W0n        R V n        RV n        \        4       V n        R# )FN)Ú
_schedulerÚ_fnÚ	_intervalÚ
_cancelledÚ_runnerr   Ú_context)Úselfr
   r   r   s   &&&&r   Ú__init__ÚScheduledHandle.__init__+   s(   € Ø#ŒØŒØ!ŒØˆŒØ37ˆŒä$›ˆŽr   c               ó   € V ^8„  d   QhRR/# )r	   ÚreturnÚboolr   )r   s   "r   r   r   5   s   € ÷ ñ ˜4ñ r   c                	ó   € V P                   # ©N)r   ©r   s   &r   Ú	cancelledÚScheduledHandle.cancelled4   s   € à�‰Ðr   Nc               ó    € V ^8„  d   QhRRRR/# )r	   ÚwaitúOptional[float]r!   ÚNoner   )r   s   "r   r   r   8   s   € ÷ ,ñ ,˜?ð ,°dñ ,r   c                ó<   € V P                   P                  W4       R# )u¹   Stop future runs.  ``wait`` (seconds) additionally blocks until an
in-flight run of this callback finishes â€” the analogue of
``thread.join(timeout=wait)`` on the old per-child thread.N)r   Ú_cancel)r   r)   s   &&r   ÚcancelÚScheduledHandle.cancel8   s   € ð 	�‰×Ñ Ö+r   )r   r   r   r   r   r   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú	__slots__r   Úpropertyr&   r.   Ú__static_attributes__r   r   r   r   r   &   s-   † Ù;àW€Iõ'ð ôó ð÷,ó ,r   r   c                  ój   € ] tR t^?tR R ltR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
RtR# )r   c               ó   € V ^8„  d   QhRR/# ©r	   r!   r+   r   )r   s   "r   r   ÚPeriodicScheduler.__annotate__@   s   € ÷ 8ñ 8˜$ñ 8r   c                	óŠ   € \         P                  ! 4       V n        . V n        \        P
                  ! 4       V n        R V n        R # r$   )Ú	threadingÚ	ConditionÚ_condÚ_heapÚ	itertoolsÚcountÚ_seqÚ_threadr%   s   &r   r   ÚPeriodicScheduler.__init__@   s.   € Ü×(Ò(Ó*ˆŒ
ØˆŒ
Ü—O’OÓ%ˆŒ	Ø37ˆŽr   c               ó$   € V ^8„  d   QhRRRRRR/# ©r	   r   r   r   r   r!   r   r   )r   s   "r   r   r;   F   s"   € ÷ ñ Ð/ð ¸5ð À_ñ r   c                	óÐ  € \        W\        V4      4      pV P                  ;_uu_ 4        V P                  V4       V P                  e!   V P                  P                  4       '       gG   \        P                  ! V P                  \        RR7      V n        V P                  P                  4        V P                  P                  4        R R R 4       V#   + '       g   i     T# ; i)NT)ÚtargetÚnameÚdaemon)r   r   r?   Ú_requeuerD   Úis_aliver=   ÚThreadÚ_runÚ_THREAD_NAMEÚstartÚnotify)r   r   r   Úhandles   &&& r   ÚscheduleÚPeriodicScheduler.scheduleF   s™   € Ü  ¬5°«?Ó;ˆØ�Z�Z‹ZØ�M‰M˜&Ô!Ø�|‰|Ò#¨4¯<©<×+@Ñ+@×+BÒ+BÜ(×/Ò/°t·y±yÄ|Ð\`Ôa�”Ø—‘×"Ñ"Ô$Ø�J‰J×ÑÔ÷ ð ˆ÷ ŽZð ˆús   ª?CÁ*A CÃC%	c               ó$   € V ^8„  d   QhRRRRRR/# )r	   rS   r   r)   r*   r!   r+   r   )r   s   "r   r   r;   P   s!   € ÷ ñ ˜oð °_ð Èñ r   c                	ó8  € V P                   ;_uu_ 4        R Vn        V P                   P                  4        VP                  pRRR4       V'       d5   Xe/   \        P
                  ! 4       VJd   VP                  V4       R# R# R# R#   + '       g   i     LN; i©TN)r?   r   rR   r   r=   Úcurrent_threadÚjoin)r   rS   r)   Úrunners   &&& r   r-   ÚPeriodicScheduler._cancelP   sj   € Ø�Z�Z‹ZØ $ˆFÔØ�J‰J×ÑÔØ—^‘^ˆF÷ ÷ �FÒ&¬9×+CÒ+CÓ+EÈVÓ+SØ�K‰K˜Öñ ,TÑ&‰4÷	 �Zús   •.B	Â	B	c               ó    € V ^8„  d   QhRRRR/# ©r	   rS   r   r!   r+   r   )r   s   "r   r   r;   X   s   € ÷ $ñ $ ð $°Dñ $r   c           	     ó°  € \         P                  ! V P                  V3\         R\	        V4      R 2RR7      pW!n         VP                  4        R#   \         dy    RTn        \        P                  RTP                  TP                  RR7       TP                  '       g/   T P                  T4       T P                  P                  4         R#  R# i ; i)zyStart ``handle``'s body on its own worker.  Called with ``_cond`` held
so ``cancel`` can never observe a half-set runner.Ú-ÚxT)rI   ÚargsrJ   rK   Nz=failed to start periodic callback worker %r; retrying in %s s©Úexc_info)r=   rN   Ú_run_callbackÚ_CALLBACK_THREAD_PREFIXÚidr   rQ   Ú	ExceptionÚloggerÚwarningr   r   r   rL   r?   rR   )r   rS   r[   s   && r   Ú	_dispatchÚPeriodicScheduler._dispatchX   s»   € ô ×!Ò!Ø×%Ñ%Ø�Ü+Ð,¨A¬b°«j¸¨^Ð<Øô	
ˆð  Œð	$Ø�L‰LŽNøÜô 
	$Ø!ˆFŒNÜ�N‰NØOØ—
‘
Ø× Ñ Øð	 ô ð ×$×$Ð$Ø—‘˜fÔ%Ø—
‘
×!Ñ!×#ò %ð
	$ús   Á A ÁACÂ#+CÃCc               ó    € V ^8„  d   QhRRRR/# r^   r   )r   s   "r   r   r;   p   s   € ÷ cñ c˜ð c°4ñ cr   c                ó¼   € \         P                  ! V P                  \        P                  ! 4       VP
                  ,           \        V P                  4      V34       R# )z1Push ``handle``'s next due time (``_cond`` held).N)ÚheapqÚheappushr@   ÚtimeÚ	monotonicr   ÚnextrC   )r   rS   s   &&r   rL   ÚPeriodicScheduler._requeuep   s6   € ä�Š�t—z‘z¤D§N¢NÓ$4°v×7GÑ7GÕ$GÌÈdÏiÉiËÐZ`Ð#aÖbr   c               ó    € V ^8„  d   QhRRRR/# r^   r   )r   s   "r   r   r;   t   s   € ÷ $ñ $ Oð $¸ñ $r   c           	     	óÜ  € R p VP                   P                  VP                  4      R J pV P                  ;_uu_ 4        RVn        V'       d	   RVn        M#VP                  '       g   V P                  V4       V P                  P                  4        RRR4       R#   \         d&    \        P                  RTP                  RR7        L¢i ; i  + '       g   i     R# ; i  T P                  ;_uu_ 4        RTn        T'       d	   RTn        M#TP                  '       g   T P                  T4       T P                  P                  4        RRR4       i   + '       g   i     i ; i; i)Fzperiodic callback %r raisedTrc   N)r   Úrunr   rh   ri   Údebugr?   r   r   rL   rR   )r   rS   Ústops   && r   re   ÚPeriodicScheduler._run_callbackt   s÷   € Øˆð	$Ø—?‘?×&Ñ& v§z¡zÓ2°eÐ;ˆDð ——“Ø!%�”ßØ(,�FÕ%Ø×*×*Ð*Ø—M‘M &Ô)Ø—
‘
×!Ñ!Ô#÷ ‘øô ô 	SÜ�L‰LÐ6¸¿
¹
ÈTˆLÖRð	Sú÷ —�û�——“Ø!%�”ßØ(,�FÕ%Ø×*×*Ð*Ø—M‘M &Ô)Ø—
‘
×!Ñ!Ô#÷ ——�ýsR   „'B ¿)CÁ)+CÂ-CÃC% ÃCÃC% ÃC"	Ã%E+Ã:)E	Ä$+E	Å	E+ÅE(Å#E+c               ó   € V ^8„  d   QhRR/# r:   r   )r   s   "r   r   r;   ƒ   s   € ÷ ñ �dñ r   c                	óD  €  V P                   ;_uu_ 4         V P                  '       g   V P                   P                  4        K/  V P                  ^ ,          w  rpVP                  '       d#   \        P
                  ! V P                  4       Ky  V\        P                  ! 4       ,
          pV^ 8”  d   V P                   P                  V4       K¹  \        P
                  ! V P                  4       V P                  V4        RRR4       EK    + '       g   i     EK  ; irX   )	r?   r@   r)   r   ro   Úheappoprq   rr   rk   )r   ÚdueÚ_rS   Údelays   &    r   rO   ÚPeriodicScheduler._runƒ   s±   € ØØ——“ØØŸ:Ÿ:˜:ØŸ
™
Ÿ™Ô)Ù Ø%)§Z¡Z°¥]‘N�C˜FØ×(×(Ð(ÜŸš d§j¡jÔ1Ù Ø¤$§.¢.Ó"2Õ2�EØ˜q”yØŸ
™
Ÿ™¨Ô.Ù Ü—M’M $§*¡*Ô-Ø—N‘N 6Ô*Ø÷ ——”ús   –DªCDÄD	)r?   r@   rC   rD   N)r0   r1   r2   r3   r   rT   r-   rk   rL   re   rO   r7   r   r   r   r   r   ?   s+   † õ8õõõ$õ0cõ$÷ñ r   r   c               ó$   € V ^8„  d   QhRRRRRR/# rG   r   )r   s   "r   r   r   š   s"   € ÷ +ñ +Ð%ð +°ð +¸?ñ +r   c                ó,   € \         P                  W4      # )zARun ``fn()`` every ``interval`` seconds via the shared scheduler.)Ú_DEFAULTrT   )r   r   s   &&r   rT   rT   š   s   € ä×Ñ˜RÓ*Ð*r   )r4   Ú
__future__r   Úcontextvarsr   ro   rA   Úloggingr=   rq   Útypingr   r   Ú	getLoggerr0   ri   rP   rf   r   r   r„   rT   r   r   r   Ú<module>rŠ      se   ðñõ* #å $Û Û Û Û Û ß %à	×	Ò	˜8Ó	$€à*€Ø4Ð ÷,ñ ,÷2Uñ Uñp Ó€÷+r   