
    hb                         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j4                  dej6                  fdZ G d d      Zy)zBase Execution Pool.    N)AnyDict)ExceptionInfo)WorkerLostError)	safe_repr)WorkerShutdownWorkerTerminatereraise)timer2)
get_logger)truncate)BasePoolapply_targetzcelery.pool c	           	         |si n|}|r ||xs  |        |              	  | |i |}
 ||
       y# |$ r  t         $ r  t        t        f$ r  t        $ rh}	 t	        t
        t        t        |            t        j                         d          n$# t
        $ r  |t                      Y nw xY wY d}~yY d}~yd}~ww xY w)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excs               S/var/www/Befach/backend/env/lib/python3.12/site-packages/celery/concurrency/base.pyr   r      s     R6Fvx5d%f% 	   O,  &	&O_T#Y%?LLN1%' 	&]_%	&%'&s3   2 &C 8BB;B.+B;-B..B;;C c                      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	 	 d dZd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd!dZd Zd Zd Zd Z d Z!d Z"d"dZ#de$e%e&f   fdZ'e(d        Z)e(d        Z*e(d        Z+y)#r   z
Task pool.   r      TFNc                 X    || _         || _        || _        || _        || _        || _        y N)limitputlocksoptionsforking_enablecallbacks_propagateapp)selfr*   r+   r-   r.   r/   r,   s          r$   __init__zBasePool.__init__I   s.    
 ,#6     c                      y r)   r   r0   s    r$   on_startzBasePool.on_startR       r2   c                      y)NTr   r4   s    r$   did_start_okzBasePool.did_start_okU   s    r2   c                      y r)   r   r4   s    r$   flushzBasePool.flushX   r6   r2   c                      y r)   r   r4   s    r$   on_stopzBasePool.on_stop[   r6   r2   c                      y r)   r   )r0   loops     r$   register_with_event_loopz!BasePool.register_with_event_loop^   r6   r2   c                      y r)   r   r0   r   r   s      r$   on_applyzBasePool.on_applya   r6   r2   c                      y r)   r   r4   s    r$   on_terminatezBasePool.on_terminated   r6   r2   c                      y r)   r   r0   jobs     r$   on_soft_timeoutzBasePool.on_soft_timeoutg   r6   r2   c                      y r)   r   rF   s     r$   on_hard_timeoutzBasePool.on_hard_timeoutj   r6   r2   c                      y r)   r   rA   s      r$   maintain_poolzBasePool.maintain_poolm   r6   r2   c                 0    t        t        |        d      )Nz does not implement kill_jobNotImplementedErrortype)r0   r   signals      r$   terminate_jobzBasePool.terminate_jobp   s    !Dzl679 	9r2   c                 0    t        t        |        d      )Nz does not implement restartrN   r4   s    r$   restartzBasePool.restartt   s    !Dzl568 	8r2   c                 F    | j                          | j                  | _        y r)   )r<   	TERMINATE_stater4   s    r$   stopzBasePool.stopx   s    nnr2   c                 F    | j                   | _        | j                          y r)   )rV   rW   rD   r4   s    r$   	terminatezBasePool.terminate|   s    nnr2   c                     t         j                  t        j                        | _        | j                          | j                  | _        y r)   )loggerisEnabledForloggingDEBUG_does_debugr5   RUNrW   r4   s    r$   startzBasePool.start   s-    !..w}}=hhr2   c                 F    | j                   | _        | j                          y r)   )CLOSErW   on_closer4   s    r$   closezBasePool.close   s    jjr2   c                      y r)   r   r4   s    r$   re   zBasePool.on_close   r6   r2   c           
         |si n|}|sg n|}| j                   r>t        j                  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.   )r`   r\   debugr   r   rB   r+   r.   )r0   r   r   r   r,   s        r$   apply_asynczBasePool.apply_async   s     "vr4LLA)D/4!@!)F"3T:< t}}VT6 ()-151I1I(  '( 	(r2   returnc                 |    | j                   j                  dz   | j                   j                  z   | 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*   r4   s    r$   	_get_infozBasePool._get_info   s6     #nn77#=@W@WW#zz
 	
r2   c                 "    | j                         S r)   )rs   r4   s    r$   infozBasePool.info   s    ~~r2   c                 4    | j                   | j                  k(  S r)   )rW   ra   r4   s    r$   activezBasePool.active   s    {{dhh&&r2   c                     | j                   S r)   )r*   r4   s    r$   num_processeszBasePool.num_processes   s    zzr2   )NTTr   Nr)   )NN),rr   rq   __qualname____doc__ra   rd   rV   r   Timersignal_safeis_greenrW   _poolr`   uses_semaphoretask_join_will_blockbody_can_be_bufferr1   r5   r8   r:   r<   r?   rB   rD   rH   rJ   rL   rR   rT   rX   rZ   rb   rf   re   rk   r   strr   rs   propertyru   rw   ry   r   r2   r$   r   r   /   s   
CEILLE K HFEK NAE-198%
($

4S> 

     ' '  r2   r   )r{   r^   osr   timetypingr   r   billiard.einfor   billiard.exceptionsr   kombu.utils.encodingr   celery.exceptionsr   r	   r
   celery.utilsr   celery.utils.logr   celery.utils.textr   __all__r\   r   r    r   r   r   r2   r$   <module>r      sl      	 
   ( / * F F  ' &
&	M	" !!%4		2E Er2   