o
    Dfb                     @   s   d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ dZedZdddddejdejfddZG dd dZdS )zBase Execution Pool.    N)AnyDict)ExceptionInfo)WorkerLostError)	safe_repr)WorkerShutdownWorkerTerminatereraise)timer2)
get_logger)truncate)BasePoolapply_targetzcelery.pool c	                 K   s   |si n|}|r||p| |  z	| |i |}
W nP |y"     t y)     ttfy2     tyj } z-ztttt|t d  W n tyW   |t	  Y nw W Y d}~dS W Y d}~dS d}~ww ||
 dS )z#Apply function within pool context.   N)
	Exceptionr   r   BaseExceptionr	   r   reprsysexc_infor   )targetargskwargscallbackaccept_callbackpidgetpid	propagate	monotonic_retexcr   r   P/home/ubuntu/webapp/venv/lib/python3.10/site-packages/celery/concurrency/base.pyr      s0   
r   c                   @   s  e Zd ZdZdZdZdZejZdZ	dZ
dZdZdZdZdZdZ		d8d	d
Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd9dd Zd!d" Zd#d$ Zd%d& Zd'd( Z d)d* Z!d+d, Z"d:d-d.Z#d/e$e%e&f fd0d1Z'e(d2d3 Z)e(d4d5 Z*e(d6d7 Z+dS );r   z
Task pool.   r      TFNr   c                 K   s(   || _ || _|| _|| _|| _|| _d S N)limitputlocksoptionsforking_enablecallbacks_propagateapp)selfr&   r'   r)   r*   r+   r(   r   r   r"   __init__I   s   
zBasePool.__init__c                 C      d S r%   r   r,   r   r   r"   on_startR      zBasePool.on_startc                 C   s   dS )NTr   r/   r   r   r"   did_start_okU   r1   zBasePool.did_start_okc                 C   r.   r%   r   r/   r   r   r"   flushX   r1   zBasePool.flushc                 C   r.   r%   r   r/   r   r   r"   on_stop[   r1   zBasePool.on_stopc                 C   r.   r%   r   )r,   loopr   r   r"   register_with_event_loop^   r1   z!BasePool.register_with_event_loopc                 O   r.   r%   r   r,   r   r   r   r   r"   on_applya   r1   zBasePool.on_applyc                 C   r.   r%   r   r/   r   r   r"   on_terminated   r1   zBasePool.on_terminatec                 C   r.   r%   r   r,   jobr   r   r"   on_soft_timeoutg   r1   zBasePool.on_soft_timeoutc                 C   r.   r%   r   r:   r   r   r"   on_hard_timeoutj   r1   zBasePool.on_hard_timeoutc                 O   r.   r%   r   r7   r   r   r"   maintain_poolm   r1   zBasePool.maintain_poolc                 C      t t|  d)Nz does not implement kill_jobNotImplementedErrortype)r,   r   signalr   r   r"   terminate_jobp      zBasePool.terminate_jobc                 C   r?   )Nz does not implement restartr@   r/   r   r   r"   restartt   rE   zBasePool.restartc                 C   s   |    | j| _d S r%   )r4   	TERMINATE_stater/   r   r   r"   stopx      zBasePool.stopc                 C      | j | _|   d S r%   )rG   rH   r9   r/   r   r   r"   	terminate|   rJ   zBasePool.terminatec                 C   s"   t tj| _|   | j| _d S r%   )loggerisEnabledForloggingDEBUG_does_debugr0   RUNrH   r/   r   r   r"   start   s   zBasePool.startc                 C   rK   r%   )CLOSErH   on_closer/   r   r   r"   close   rJ   zBasePool.closec                 C   r.   r%   r   r/   r   r   r"   rU      r1   zBasePool.on_closec                 K   sb   |si n|}|s
g n|}| j r!td|tt|dtt|d | j|||f| j| jd|S )zEquivalent of the :func:`apply` built-in function.

        Callbacks should optimally return as soon as possible since
        otherwise the thread which handles the result will get blocked.
        z&TaskPool: Apply %s (args:%s kwargs:%s)i   )waitforslotr*   )rQ   rM   debugr   r   r8   r'   r*   )r,   r   r   r   r(   r   r   r"   apply_async   s   zBasePool.apply_asyncreturnc                 C   s   | j jd | j j | jdS )z
        Return configuration and statistics information. Subclasses should
        augment the data as required.

        :return: The returned value must be JSON-friendly.
        :)implementationzmax-concurrency)	__class__
__module____name__r&   r/   r   r   r"   	_get_info   s   zBasePool._get_infoc                 C   s   |   S r%   )r`   r/   r   r   r"   info   s   zBasePool.infoc                 C   s   | j | jkS r%   )rH   rR   r/   r   r   r"   active   s   zBasePool.activec                 C   s   | j S r%   )r&   r/   r   r   r"   num_processes   s   zBasePool.num_processes)NTTr   Nr%   )NN),r_   r^   __qualname____doc__rR   rT   rG   r
   Timersignal_safeis_greenrH   _poolrQ   uses_semaphoretask_join_will_blockbody_can_be_bufferr-   r0   r2   r3   r4   r6   r8   r9   r<   r=   r>   rD   rF   rI   rL   rS   rV   rU   rY   r   strr   r`   propertyra   rb   rc   r   r   r   r"   r   /   sT    
	



r   )re   rO   osr   timetypingr   r   billiard.einfor   billiard.exceptionsr   kombu.utils.encodingr   celery.exceptionsr   r   r	   celery.utilsr
   celery.utils.logr   celery.utils.textr   __all__rM   r   r   r   r   r   r   r   r"   <module>   s(    
