o
    ›¨Êh¥  ã                   @   sh  d Z ddlZddlZddlZddlZddlmZ ddlmZ dZ	da
dae ¡ Zeƒ Zdadd„ Zd	d
„ Zdd„ Zdd„ ZG dd„ dejƒZeƒ Zeƒ ZejZejZdd„ Zdd„ Zdd„ Zej  !d¡ridd„ Z"nej  !d¡rtdd„ Z"neZ"dd„ Z#dd„ Z$ee"ƒZ%ee#ƒZ&d d!„ Z'd"d#„ Z(d$d%„ Z)d/d&d'„Z*d/d(d)„Z+d*d+„ Z,d,d-„ Z-ej  !d.¡r¯e,ƒ  dS e-ƒ  dS )0z�Internal state.

This is an internal module containing thread state
like the ``current_app``, and ``current_task``.

This module shouldn't be used directly.
é    N)ÚProxy)Ú
LocalStack)Úset_default_appÚget_current_appÚget_current_taskÚget_current_worker_taskÚcurrent_appÚcurrent_taskÚconnect_on_app_finalizeFc                 C   s   t  | ¡ | S )z8Connect callback to be called when any app is finalized.)Ú_on_app_finalizersÚadd)Úcallback© r   ú?/var/www/html/env/lib/python3.10/site-packages/celery/_state.pyr
   +   s   
r
   c                 C   s   t tƒ}|D ]}|| ƒ qd S ©N)Úsetr   )ÚappÚ	callbacksr   r   r   r   Ú_announce_app_finalized1   s   
ÿr   c                 C   s   | a d S r   ©Ú_task_join_will_block)Úblocksr   r   r   Ú_set_task_join_will_block7   ó   r   c                   C   ó   t S r   r   r   r   r   r   Útask_join_will_block<   ó   r   c                   @   s   e Zd ZdZdS )Ú_TLSN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   @   s    r   c                 C   s   | a dS )zSet default app.N)Údefault_app©r   r   r   r   r   V   ó   r   c                  C   s>   t d u rddlm}  t| dg dtj d¡pdd�ƒ tjpt S )Nr   ©ÚCeleryÚdefaultFÚCELERY_LOADER)ÚfixupsÚset_as_currentÚloader)	r!   Úcelery.app.baser%   r   ÚosÚenvironÚgetÚ_tlsr   r$   r   r   r   Ú_get_current_app\   s   þ
r0   c                 C   s
   | t _d S r   )r/   r   r"   r   r   r   Ú_set_current_appg   s   
r1   ÚC_STRICT_APPc                   C   s   t dƒ‚)zReturn the current app.zUSES CURRENT APP)ÚRuntimeErrorr   r   r   r   r   l   r   r   Ú
C_WARN_APPc                  C   s*   dd l } tdtjd� | jtjd� tƒ S )Nr   z-- USES CURRENT_APP)Úfile)Ú	tracebackÚprintÚsysÚstderrÚprint_stackr0   )r6   r   r   r   r   p   s   c                   C   s   t jS )zCurrently executing task.)Ú_task_stackÚtopr   r   r   r   r   y   s   r   c                  C   s$   t tjƒD ]
} | jjs|   S qdS )zïCurrently executing task, that was applied by the worker.

    This is used to differentiate between the actual task
    executed by the worker and any task that was called within
    a task (using ``task.__call__`` or ``task.apply``)
    N)Úreversedr;   ÚstackÚrequestÚcalled_directly)Útaskr   r   r   r   ~   s
   ÿÿr   c                 C   ó   t  | ¡ d S r   )Ú_appsr   r"   r   r   r   Ú_register_app‘   ó   rD   c                 C   rB   r   )rC   Údiscardr"   r   r   r   Ú_deregister_app•   rE   rG   c                   C   r   r   )rC   r   r   r   r   Ú_get_active_apps™   r   rH   c                 C   s   | d u rt ƒ S | S r   )r   r"   r   r   r   Ú_app_or_default�   s   rI   c                 C   sŠ   ddl m} zddlm} W n ty   d }Y nw | d u rCttdd ƒr.tdƒ |ƒ  tjS |r6|ƒ j	dkr:t
dƒ‚tdƒ |ƒ  tS | S )	Nr   )r:   )Úcurrent_processr   z-- RETURNING TO CURRENT APP --ÚMainProcesszDEFAULT APPz-- RETURNING TO DEFAULT APP --)r6   r:   Úbilliard.processrJ   ÚImportErrorÚgetattrr/   r7   r   Ú_nameÚ	Exceptionr!   )r   r:   rJ   r   r   r   Ú_app_or_default_trace£   s"   ÿrQ   c                   C   ó   t adS )z Enable tracing of app instances.N)rQ   Úapp_or_defaultr   r   r   r   Úenable_trace¶   r#   rT   c                   C   rR   )z!Disable tracing of app instances.N)rI   rS   r   r   r   r   Údisable_trace¼   r#   rU   ÚCELERY_TRACE_APPr   ).Ú__doc__r,   r8   Ú	threadingÚweakrefÚcelery.localr   Úcelery.utils.threadsr   Ú__all__r!   rS   ÚWeakSetrC   r   r   r   r
   r   r   r   Úlocalr   r/   r;   ÚpushÚpush_current_taskÚpopÚpop_current_taskr   r0   r1   r-   r.   r   r   r   r   r	   rD   rG   rH   rI   rQ   rT   rU   r   r   r   r   Ú<module>   sX    





