o
    wvXj  ã                   @   s|  d Z ddlmZmZm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¡rsdd„ Z&nej$ %d¡r~d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-d0d'd(„Z.d0d)d*„Z/d+d,„ Z0d-d.„ Z1ej$ %d/¡r¹e0ƒ  dS e1ƒ  dS )1z�Internal state.

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

This module shouldn't be used directly.
é    )Úabsolute_importÚprint_functionÚunicode_literalsN)Ú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   úJ/var/www/html/myproject/venv/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_finalized3   s   
ÿr   c                 C   s   | a d S r   ©Ú_task_join_will_block)Úblocksr   r   r   Ú_set_task_join_will_block9   ó   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    B   s    r    c                 C   s   | a dS )zSet default app.N)Údefault_app©r   r   r   r   r   X   ó   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   þ
r3   c                 C   s
   | t _d S r   )r2   r   r%   r   r   r   Ú_set_current_appi   s   
r4   ÚC_STRICT_APPc                   C   s   t dƒ‚)zReturn the current app.zUSES CURRENT APP)ÚRuntimeErrorr   r   r   r   r   n   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_stackr3   )r9   r   r   r   r   r   s   c                   C   s   t jS )zCurrently executing task.)Ú_task_stackÚtopr   r   r   r   r	   {   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“   ó   rG   c                 C   rE   r   )rF   Údiscardr%   r   r   r   Ú_deregister_app—   rH   rJ   c                   C   r   r   )rF   r   r   r   r   Ú_get_active_apps›   r   rK   c                 C   s   | d u rt ƒ S | S r   )r   r%   r   r   r   Ú_app_or_defaultŸ   s   rL   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 --)r9   r=   Úbilliard.processrM   ÚImportErrorÚgetattrr2   r:   r   Ú_nameÚ	Exceptionr$   )r   r=   rM   r   r   r   Ú_app_or_default_trace¥   s"   ÿrT   c                   C   ó   t adS )z Enable tracing of app instances.N)rT   Úapp_or_defaultr   r   r   r   Úenable_trace¸   r&   rW   c                   C   rU   )z!Disable tracing of app instances.N)rL   rV   r   r   r   r   Údisable_trace¾   r&   rX   ÚCELERY_TRACE_APPr   )2Ú__doc__Ú
__future__r   r   r   r/   r;   Ú	threadingÚweakrefÚcelery.localr   Úcelery.utils.threadsr   Ú__all__r$   rV   ÚWeakSetrF   r   r   r   r   r   r   r   Úlocalr    r2   r>   ÚpushÚpush_current_taskÚpopÚpop_current_taskr   r3   r4   r0   r1   r   r	   r
   r   r   rG   rJ   rK   rL   rT   rW   rX   r   r   r   r   Ú<module>   sZ   





