o
    Df                     @   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.re,  dS e-  dS )0zInternal 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   F/home/ubuntu/webapp/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_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 )zCurrently 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    





