§
    ¨MºfÝ  ã                   óŒ   — 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	Z G d
„ de¦  «        Zd„ Z G d„ de¦  «        ZdS )é    N)Úcopy_contexté   )ÚBaseLongCallbackManageré   )Úcontext_value)ÚAttributeDict)ÚPreventUpdatez__$pending__c                   ó\   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zd„ Zdd„Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zˆ xZS )ÚDiskcacheManagerz^Manage the background execution of callbacks with subprocesses and a diskcache result backend.Nc                 óT  •— 	 ddl }ddl}ddl}n"# t          $ r}t          d¦  «        |‚d}~ww xY w|€|                     ¦   «         | _        n2t          ||j        |j        f¦  «        st          d¦  «        ‚|| _        || _	        t          ¦   «                              |¦  «         dS )a©  
        Long callback manager that runs callback logic in a subprocess and stores
        results on disk using diskcache

        :param cache:
            A diskcache.Cache or diskcache.FanoutCache instance. See the diskcache
            documentation for information on configuration options. If not provided,
            a diskcache.Cache instance will be created with default values.
        :param cache_by:
            A list of zero-argument functions.  When provided, caching is enabled and
            the return values of these functions are combined with the callback
            function's input arguments and source code to generate cache keys.
        :param expire:
            If provided, a cache entry will be removed when it has not been accessed
            for ``expire`` seconds.  If not provided, the lifetime of cache entries
            is determined by the default behavior of the ``cache`` instance.
        r   Nz{DiskcacheLongCallbackManager requires extra dependencies which can be installed doing

    $ pip install "dash[diskcache]"
zHFirst argument must be a diskcache.Cache or diskcache.FanoutCache object)Ú	diskcacheÚpsutilÚmultiprocessÚImportErrorÚCacheÚhandleÚ
isinstanceÚFanoutCacheÚ
ValueErrorÚexpireÚsuperÚ__init__)	ÚselfÚcacheÚcache_byr   r   r   r   Úmissing_importsÚ	__class__s	           €úl/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/dash/long_callback/managers/diskcache_manager.pyr   zDiskcacheManager.__init__   sâ   ø€ ð$
	#ØÐÐÐØˆMˆMˆMØÐÐÐÐøÝð 	#ð 	#ð 	#Ýð)ñô ð
 #ð#øøøøð	#øøøð ˆ=Ø#Ÿ/š/Ñ+Ô+ˆDŒKˆKå˜e i¤o°yÔ7LÐ%MÑNÔNð Ý ð6ñô ð ð  ˆDŒKàˆŒÝ‰Œ×Ò˜Ñ"Ô"Ð"Ð"Ð"s   ƒ �
/š*ª/c                 ó  — dd l }|€d S t          |¦  «        }| j                             ¦   «         5  |                     |¦  «        r§|                     |¦  «        }|                     d¬¦  «        D ]'}	 |                     ¦   «          Œ# |j        $ r Y Œ$w xY w	 |                     ¦   «          n# |j        $ r Y nw xY w	 | 	                    d¦  «         n# |j
        |j        f$ r Y nw xY wd d d ¦  «         d S # 1 swxY w Y   d S )Nr   T)Ú	recursiver   )r   Úintr   ÚtransactÚ
pid_existsÚProcessÚchildrenÚkillÚNoSuchProcessÚwaitÚTimeoutExpired)r   Újobr   ÚprocessÚprocs        r   Úterminate_jobzDiskcacheManager.terminate_job:   s�  € Øˆˆˆàˆ;ØˆFå�#‰hŒhˆð Œ[×!Ò!Ñ#Ô#ð 	ð 	Ø× Ò  Ñ%Ô%ð Ø Ÿ.š.¨Ñ-Ô-�à#×,Ò,°tÐ,Ñ<Ô<ð ð �DðØŸ	š	™œ˜˜øØ!Ô/ð ð ð Ø˜ðøøøðØ—L’L‘N”N�N�NøØÔ+ð ð ð Ø�DðøøøðØ—L’L ‘O”O�O�OøØÔ-¨vÔ/CÐDð ð ð Ø�Dðøøøð#	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s~   ±AC;Á5B
Â	C;Â

BÂC;ÂBÂC;ÂB0Â/C;Â0
B=Â:C;Â<B=Â=C;ÃCÃC;ÃC+Ã(C;Ã*C+Ã+C;Ã;C?ÄC?c                 ó²   — dd l }t          |¦  «        }|rA|                     |¦  «        r,|                      |¦  «        s|                      |¦  «         dS dS )Nr   TF)r   r!   r#   Újob_runningr-   )r   r*   r   s      r   Úterminate_unhealthy_jobz(DiskcacheManager.terminate_unhealthy_jobX   sg   € Øˆˆˆå�#‰hŒhˆàð 	�6×$Ò$ SÑ)Ô)ð 	Ø×#Ò# CÑ(Ô(ð Ø×"Ò" 3Ñ'Ô'Ð'Ø�tàˆuó    c                 ó¾   — dd l }t          |¦  «        }|rG|                     |¦  «        r2|                     |¦  «        }|                     ¦   «         |j        k    S dS )Nr   F)r   r!   r#   r$   ÚstatusÚSTATUS_ZOMBIE)r   r*   r   r,   s       r   r/   zDiskcacheManager.job_runningd   s_   € Øˆˆˆå�#‰hŒhˆàð 	9�6×$Ò$ SÑ)Ô)ð 	9Ø—>’> #Ñ&Ô&ˆDØ—;’;‘=”= FÔ$8Ò8Ð8Øˆur1   c                 ó.   — t          || j        |¦  «        S ©N)Ú_make_job_fnr   )r   ÚfnÚprogressÚkeys       r   Úmake_job_fnzDiskcacheManager.make_job_fnn   s   € Ý˜B ¤¨XÑ6Ô6Ð6r1   c                 ó:   — | j                              |¦  «         d S r6   )r   Údelete©r   r:   s     r   Úclear_cache_entryz"DiskcacheManager.clear_cache_entryq   s   € ØŒ×Ò˜3ÑÔÐÐÐr1   c                 óŒ   — ddl m}  ||||                      |¦  «        ||f¬¦  «        }|                     ¦   «          |j        S )Nr   )r$   )ÚtargetÚargs)r   r$   Ú_make_progress_keyÚstartÚpid)r   r:   Újob_fnrB   Úcontextr$   r,   s          r   Úcall_job_fnzDiskcacheManager.call_job_fnu   s^   € à(Ð(Ð(Ð(Ð(Ð(ð ˆwØ  d×&=Ò&=¸cÑ&BÔ&BÀDÈ'Ð Rð
ñ 
ô 
ˆð 	�
Š
‰ŒˆØŒxˆr1   c                 óœ   — |                       |¦  «        }| j                             |¦  «        }|r| j                             |¦  «         |S r6   )rC   r   Úgetr=   )r   r:   Úprogress_keyÚprogress_datas       r   Úget_progresszDiskcacheManager.get_progress€   sL   € Ø×.Ò.¨sÑ3Ô3ˆØœŸš¨Ñ5Ô5ˆØð 	-ØŒK×Ò˜|Ñ,Ô,Ð,àÐr1   c                 ó:   — | j                              |¦  «        d uS r6   )r   rJ   r>   s     r   Úresult_readyzDiskcacheManager.result_readyˆ   s   € ØŒ{�Š˜sÑ#Ô#¨4Ð/Ð/r1   c                 ón  — | j                              || j        ¦  «        }|| j        u r| j        S | j        €|                      |¦  «         n(| j        r!| j                              || j        ¬¦  «         |                      |                      |¦  «        ¦  «         |r|                      |¦  «         |S )N)r   )	r   rJ   Ú	UNDEFINEDr   r?   r   ÚtouchrC   r-   )r   r:   r*   Úresults       r   Ú
get_resultzDiskcacheManager.get_result‹   s¹   € à”—’  d¤nÑ5Ô5ˆØ�T”^Ð#Ð#Ø”>Ð!ð Œ=Ð Ø×"Ò" 3Ñ'Ô'Ð'Ð'àŒ{ð ;Ø”×!Ò! #¨d¬kÐ!Ñ:Ô:Ð:à×Ò˜t×6Ò6°sÑ;Ô;Ñ<Ô<Ð<àð 	$Ø×Ò˜sÑ#Ô#Ð#Øˆr1   )NNNr6   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r-   r0   r/   r;   r?   rH   rM   rO   rT   Ú__classcell__)r   s   @r   r   r      sÐ   ø€ € € € € ØhÐhð)#ð )#ð )#ð )#ð )#ð )#ðVð ð ð<
ð 
ð 
ðð ð ð7ð 7ð 7ð 7ð ð  ð  ð	ð 	ð 	ðð ð ð0ð 0ð 0ðð ð ð ð ð ð r1   r   c                 ó   ‡ ‡‡— ˆˆ ˆfd„}|S )Nc                 ó†   •‡ ‡‡‡‡— ˆˆfd„}‰
r|gng Št          ¦   «         }ˆˆˆ	ˆˆ ˆfd„}|                     |¦  «         d S )Nc                 ór   •— t          | t          t          f¦  «        s| g} ‰                     ‰| ¦  «         d S r6   )r   ÚlistÚtupleÚset)Úprogress_valuer   rK   s    €€r   Ú_set_progressz3_make_job_fn.<locals>.job_fn.<locals>._set_progress¡   s;   ø€ Ý˜n­tµU¨mÑ<Ô<ð 2Ø"0Ð!1�à�IŠI�l NÑ3Ô3Ð3Ð3Ð3r1   c                  ó  •— t          di ‰¤Ž} d| _        t          j        | ¦  «         	 t	          ‰t
          ¦  «        r	 ‰‰i ‰¤Ž}n1t	          ‰t          t          f¦  «        r ‰g ‰¢‰¢R Ž }n
 ‰g ‰¢‰‘R Ž }‰                     ‰|¦  «         d S # t          $ r ‰                     ‰ddi¦  «         Y d S t          $ rD}‰                     ‰dt          |¦  «        t          j        ¦   «         dœi¦  «         Y d }~d S d }~ww xY w)NFÚ_dash_no_updateÚlong_callback_error)ÚmsgÚtb© )r   Úignore_register_pager   r_   r   Údictr]   r^   r	   Ú	ExceptionÚstrÚ	tracebackÚ
format_exc)	ÚcÚuser_callback_outputÚerrr   rG   r8   Úmaybe_progressÚ
result_keyÚuser_callback_argss	      €€€€€€r   Úrunz)_make_job_fn.<locals>.job_fn.<locals>.run«   s‰  ø€ ÝÐ(Ð( Ð(Ð(ˆAØ%*ˆAÔ"ÝÔ˜aÑ Ô Ð ð<ÝÐ0µ$Ñ7Ô7ð SØ+-¨2¨~Ð+TÐASÐ+TÐ+TÐ(Ð(ÝÐ 2µT½5°MÑBÔBð SØ+-¨2Ð+S¨~Ð+SÐ@RÐ+SÐ+SÐ+SÐ(Ð(à+-¨2Ð+R¨~Ð+RÐ?QÐ+RÐ+RÐ+RÐ(ð —	’	˜*Ð&:Ñ;Ô;Ð;Ð;Ð;øõ !ð Nð Nð NØ—	’	˜*Ð'8Ð:KÐ&LÑMÔMÐMÐMÐMÐMÝð 	ð 	ð 	Ø—	’	Øà-Ý#& s¡8¤8Ý"+Ô"6Ñ"8Ô"8ð0ð 0ðñô ð ð ð ð ð ð ð øøøøð	øøøs   ªAB Â"DÂ6	DÂ?9C>Ã>D)r   rt   )rr   rK   rs   rG   ra   Úctxrt   rq   r   r8   r9   s   ````   @€€€r   rF   z_make_job_fn.<locals>.job_fn    sˆ   øøøøøø€ ð	4ð 	4ð 	4ð 	4ð 	4ð 	4ð -5Ð<˜-˜˜¸"ˆå‰nŒnˆð	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð4 	�Š�‰Œˆˆˆr1   rg   )r8   r   r9   rF   s   ``` r   r7   r7   Ÿ   s0   øøø€ ð%ð %ð %ð %ð %ð %ð %ðN €Mr1   c                   ó   — e Zd ZdZdS )ÚDiskcacheLongCallbackManagerz<Deprecated: use `from dash import DiskcacheManager` instead.N)rU   rV   rW   rX   rg   r1   r   rw   rw   Ê   s   € € € € € ØFÐFÐFÐFr1   rw   )rl   Úcontextvarsr   Ú r   Ú_callback_contextr   Ú_utilsr   Ú
exceptionsr	   Ú_pending_valuer   r7   rw   rg   r1   r   ú<module>r~      só   ðØ Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $à %Ð %Ð %Ð %Ð %Ð %Ø .Ð .Ð .Ð .Ð .Ð .Ø #Ð #Ð #Ð #Ð #Ð #Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à€ðPð Pð Pð Pð PÐ.ñ Pô Pð Pðf(ð (ð (ðVGð Gð Gð Gð GÐ#3ñ Gô Gð Gð Gð Gr1   