Ë
    3ýj–\  ã                   óÌ  — 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dl	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mZ dd
lmZ ddlmZ ddlmZmZmZmZ ddlm Z 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dl0m1Z1 ddl2m3Z3 dZ4 e'e5«      Z6ej                  jo                  d«      Z8 e9ed«      Z:g d¢Z;dZ<dZ=d„ Z>ej~                  fd„Z@ G d„ de1«      ZAd d!ded"fd#eAfd$„ZBd#eAfd%„ZCd#eAfd&„ZDd#eAfd'„ZEe
d(k(  r eeBd d)eEe¬*«      ZFn eeBd d!¬+«      ZFe8s eeBd(d)eEe¬*«      ZGnd,„ xZFZGd-„ ZHe8s eeBd.eHe¬/«      ZInd0„ ZId1„ ZJd6d2„ZKd7d3„ZL	 	 d8d4„ZMd6d5„ZNy)9zäWorker command-line program.

This module is the 'program-version' of :mod:`celery.worker`.

It does everything necessary to run that module
as an actual application, like installing signal handlers,
platform tweaks, and so on.
é    N)Údatetime)Úpartial)ÚREMAP_SIGTERM)Úcurrent_process)Úignore_errors)Úsafe_str)ÚVERSION_BANNERÚ_original_os_writeÚ	platformsÚsignals)Útrace)Ú	AppLoader)Ú
EX_FAILUREÚEX_OKÚcheck_privilegesÚisatty)ÚstaticÚterm)Úcry)Úqualname)Ú
get_loggerÚin_sighandlerÚset_in_sighandler)Ú	pluralize)Úbound_open_broker_sockets)Úhumanize_seconds)ÚWorkController)ÚSHUTDOWN_SOCKET_TIMEOUT)ÚWorkerÚjavaÚpypy_version_info)ú --------------ú--- ***** -----ú-- ******* ----ú- *** --- * ---ú- ** ----------r&   r&   r&   r%   r$   r#   r"   zÍ{hostname} v{version}

{platform} {timestamp}

[config]
.> app:         {app}
.> transport:   {conninfo}
.> results:     {results}
.> concurrency: {concurrency}
.> task events: {events}

[queues]
{queues}
z
[tasks]
{tasks}
c                  ó<   — ddl m}  t        d„  | «       D «       «      S )Nr   ©Ú	enumeratec              3   óV   K  — | ]!  }|j                   j                  d «      sd–— Œ# y­w)zDummy-é   N)ÚnameÚ
startswith)Ú.0Úts     úL/root/telegram-saas/.venv/lib/python3.12/site-packages/celery/apps/worker.pyú	<genexpr>z&active_thread_count.<locals>.<genexpr>P   s)   è ø€ ò 3�QØ—f‘f×'Ñ'¨Ô1ô ñ 3ùs   ‚'))Ú	threadingr)   Úsumr(   s    r0   Úactive_thread_countr4   N   s    € Ý#Üñ 3™)›+ô 3ó 3ð 3ó    c                 ó¸   — t        |d«      r?|j                  «       �.	 t        |j                  «       d| › d�j                  «       «       yyy# t        $ r Y yw xY w)a!  
    Uses the original (unpatched) os.write to avoid issues with eventlet/gevent
    monkey-patching. When using eventlet>=0.37.0, the patched os.write calls
    hubs.trampoline() which raises RuntimeError if called from within the
    hub's event loop (e.g., during signal handling).
    ÚfilenoNú
)Úhasattrr7   r
   ÚencodeÚOSError)ÚmsgÚfs     r0   Úsafe_sayr>   T   s]   € ô ˆq�(Ô §¡£
Ð 6ð	Ü˜qŸx™x›z¨R°¨u°B¨<×+>Ñ+>Ó+@ÕAð !7Ðøô ò 	ñ ð	ús   ž,A Á	AÁAc                   ó„   ‡ — e Zd ZdZdd„Z	 	 dd„Zd„ Zˆ fd„Zd„ Zd„ Z	dd„Z
d	„ Zd
„ Zdd„Zd„ Zdd„Zd„ Zd„ Zd„ Zˆ xZS )r   zWorker as a program.c                 ó:  — || _         t        j                  | j                  | j                  «       t
        j                  j                  | j                  | | j                  j                  |¬«       t        | j                  j                  j                  «       y )N)ÚsenderÚinstanceÚconfÚoptions)Úquietr   Úsetup_worker_optimizationsÚappÚhostnamer   Úceleryd_initÚsendrC   r   Úaccept_content)ÚselfrE   Úkwargss      r0   Úon_before_initzWorker.on_before_initg   sj   € ØˆŒ
Ü×(Ñ(¨¯©°4·=±=ÔAô 	×Ñ×!Ñ!Ø—=‘=¨4Ø—‘—‘¨ð 	"ô 	
ô 	˜Ÿ™Ÿ™×5Ñ5Õ6r5   c                 óV  — | j                   j                  d|«      | _        | j                   j                  d|«      | _        || _        || _        t        t        j                  «      | _	        | j                   j                  j                  | j                  |�| n|¬«      | _        y )NÚworker_redirect_stdoutsÚworker_redirect_stdouts_level)Úenabled)rG   ÚeitherÚredirect_stdoutsÚredirect_stdouts_levelÚpurgeÚno_colorr   ÚsysÚstdoutÚ_isattyÚlogÚcoloredÚlogfile)rL   rV   rW   rT   rU   rM   s         r0   Úon_after_initzWorker.on_after_inits   s‹   € ð !%§¡§¡Ø%Ð'7ó!9ˆÔà&*§h¡h§o¡oØ+Ð-Có'EˆÔ#àˆŒ
Ø ˆŒÜœcŸj™jÓ)ˆŒØ—x‘x—|‘|×+Ñ+Ø�L‰LØ$,Ð$8˜‘L¸hð ,ó 
ˆ�r5   c                 ó‚   — | j                  «       | _        t        j                  | j                  | j
                  «       y ©N)Úsetup_loggingÚ_custom_loggingr   rF   rG   rH   ©rL   s    r0   Úon_init_blueprintzWorker.on_init_blueprint‚   s-   € Ø#×1Ñ1Ó3ˆÔô 	×(Ñ(¨¯©°4·=±=ÕAr5   c                 óš  •— | j                   }t        ‰| �	  «        t        j                  j                  | j                  | |j                  ¬«       | j                  r| j                  «        | j                  s| j                  «        | j                  d«       | j                  | «       | j                  s1| j                  r%|j                   j                  | j"                  «       d}|j$                  }t'        |t(        «      r|j+                  «       dv}|r1|j                  j-                  «       rt.        j1                  d«       y y y )N)rA   rB   rC   z-active-T)zdjango.conf:settingszPlease run `celery upgrade settings path/to/settings.py` to avoid these warnings and to allow a smoother upgrade to Celery 6.0.)rG   ÚsuperÚon_startr   Úceleryd_after_setuprJ   rH   rC   rV   Úpurge_messagesrE   Úemit_bannerÚset_process_statusÚinstall_platform_tweaksrb   rT   r[   rU   Ú_config_sourceÚ
isinstanceÚstrÚlowerÚmaybe_warn_deprecated_settingsÚloggerÚwarning)rL   rG   Úwarn_deprecatedÚconfig_sourceÚ	__class__s       €r0   rg   zWorker.on_startˆ   s  ø€ Ø�h‰hˆÜ‰ÑÔô 	×#Ñ#×(Ñ(Ø—=‘=¨4°c·h±hð 	)ô 	
ð �:Š:Ø×ÑÔ!à�zŠzØ×ÑÔà×Ñ 
Ô+Ø×$Ñ$ TÔ*Ø×#Ò#¨×(=Ò(=Ø�G‰G×$Ñ$ T×%@Ñ%@ÔAð ˆØ×*Ñ*ˆÜ�m¤SÔ)ð ,×1Ñ1Ó3ð <ð ˆOñ Ø�x‰x×6Ñ6Ô8Ü—‘ð%õð 9ð r5   c                 óÌ  — t        j                  «       }|r0t        t        j                  t	        j
                  «       «      «       t        t        dj                  t        | j                  j                  d| j                  | ¬«      «      «      t        | j                  j                  | j                  «       xs d«      «      g«      «      t        j                  d¬«       y )NÚ z 
)ÚartlinesT)ÚfileÚflush)r   Úsupports_imagesÚprintÚimgcatr   Úlogor   Újoinro   r\   ÚcyanÚstartup_infoÚresetÚ
extra_inforX   Ú
__stdout__)rL   Ú	use_images     r0   rj   zWorker.emit_banner°   s©   € ô ×(Ñ(Ó*ˆ	ÙÜ”$—+‘+œfŸk™k›mÓ,Ô-ÜŒh�r—w‘wÜ�—‘×!Ñ!Ø�t×(Ñ(°i°-Ð(Ó@óBó Cä�—‘×"Ñ" 4§?¡?Ó#4Ò#:¸Ó;Ó<ð 
ó ó ô —.‘.¨ö		.r5   c                 ó–   — t         j                  j                  |¬«       t        j	                  dt        | j                  «      «       y )N)rA   z	%s ready.)r   Úworker_readyrJ   rr   Úinfor   rH   )rL   Úconsumers     r0   Úon_consumer_readyzWorker.on_consumer_ready¼   s0   € Ü×Ñ×!Ñ!¨Ð!Ô2Ü�‰�K¤¨$¯-©-Ó!8Õ9r5   c                 óÈ   — |€| j                   �| j                    }| j                  j                  j                  | j                  | j
                  d|| j                  ¬«      S )NF)rT   ÚcolorizerH   )rW   rG   r[   ÚsetupÚloglevelr]   rH   )rL   r�   s     r0   ra   zWorker.setup_loggingÀ   sU   € ØÐ §¡Ð 9ØŸ=™=Ð(ˆHØ�x‰x�|‰|×!Ñ!Ø�M‰M˜4Ÿ<™<Ø"¨XÀÇÁð "ó 
ð 	
r5   c                 ó  — | j                   j                  j                  }|€ | j                   j                  j                  }|s|j	                  «        |S d„ }|j                  || j                   j                  j                  «      S )a”  Connect to the broker, retrying if the app is configured to.

        The connection is lazy, so without this the first thing to touch it
        raises straight away. ``--purge`` runs from :meth:`on_start`, which
        makes ``broker_connection_retry_on_startup`` the setting that decides
        whether to retry, falling back to ``broker_connection_retry`` for apps
        that predate it.
        c           	      óH   — t         j                  d| t        |dd«      «       y )Nz/purge: Connection error: %s. Trying again %s...Úinú )rr   Úerrorr   )ÚexcÚintervals     r0   Ú_error_handlerz0Worker._ensure_connected.<locals>._error_handlerÙ   s    € Ü�L‰LØAØÔ% h°°cÓ:õr5   )rG   rC   Ú"broker_connection_retry_on_startupÚbroker_connection_retryÚconnectÚensure_connectionÚbroker_connection_max_retries)rL   Ú
connectionÚretryr—   s       r0   Ú_ensure_connectedzWorker._ensure_connectedÈ   sq   € ð —‘—‘×@Ñ@ˆØˆ=Ø—H‘H—M‘M×9Ñ9ˆEáØ×ÑÔ ØÐò	ð ×+Ñ+Ø˜DŸH™HŸM™M×GÑGó
ð 	
r5   c           
      ó  — | j                   j                  «       5 }| j                  |«      }| j                   j                  j	                  |¬«      }|rt        d|› dt        |d«      › d�d¬«       d d d «       y # 1 sw Y   y xY w)N)r�   zpurge: Erased r“   Úmessagez from the queue.
T)r{   )rG   Úconnection_for_writerŸ   ÚcontrolrV   r}   r   )rL   r�   Úcounts      r0   ri   zWorker.purge_messagesã   s€   € Ø�X‰X×*Ñ*Ó,ð 	l°
Ø×/Ñ/°
Ó;ˆJØ—H‘H×$Ñ$×*Ñ*°jÐ*ÓAˆEÙÜ˜ u g¨Q¬y¸À	Ó/JÐ.KÐK]Ð^ÐfjÕk÷		l÷ 	lñ 	lús   ›AA<Á<Bc                 óv   ‡‡— |j                  ˆˆfd„t        | j                  j                  «      D «       «      S )Nc              3   óT   •K  — | ]  }‰s|j                  ‰«      s
n|rd |› �–— Œ! y­w)z  . N)r-   )r.   ÚtaskÚinclude_builtinsÚint_s     €€r0   r1   z"Worker.tasklist.<locals>.<genexpr>ë   s/   øè ø€ ò 
Ø"Ù1A�D—O‘O DÕ)Átð �4�&ŒMñ
ùs   ƒ%()r€   ÚsortedrG   Útasks)rL   r¨   Úsepr©   s    ` `r0   ÚtasklistzWorker.tasklistê   s.   ù€ Ø�x‰xô 
Ü&,¨T¯X©X¯^©^Ó&<ô
ó 
ð 	
r5   c                 óâ   — | j                   €y | j                   t        j                  k  rE| j                   t        j                  k  }| j	                  |¬«      }t
        j                  |¬«      S y )N)r¨   )r«   )r�   ÚloggingÚINFOÚDEBUGr­   ÚEXTRA_INFO_FMTÚformat)rL   r¨   r­   s      r0   r„   zWorker.extra_infoð   s\   € Ø�=‰=Ð ØØ�=‰=œGŸL™LÒ(Ø#Ÿ}™}´·±Ñ=ÐØ—}‘}Ð6F�}ÓGˆHÜ!×(Ñ(¨xÐ(Ó8Ð8ð )r5   c                 óÄ  — | j                   }t        | j                  «      }dj                  |j                  xs dt        |«      «      }t        |j                  t        «      s4t        |j                  «      }|j                  d«      r|dd  }|d|› d�z  }| j                  r| j                  \  }}d|› d|› d	�}| j                  }t        |t        «      s|j                  }|d|j                  d
«      d   › d�z  }d}	| j                  sd}	t         j                  |t#        | j$                  «      t'        j(                  «       j+                  d¬«      t,        | j                   j/                  «       j1                  «       | j                   j2                  j1                  «       |t#        t5        j6                  «       «      |	|j8                  j:                  j                  dd¬«      ¬«
      j=                  «       }
|r4t?        |
«      D ]&  \  }}	 djA                  tB        |   |
|   g«      |
|<   Œ( djA                  |
«      dz   S # tD        $ r d|
|   z   |
|<   Y ŒSw xY w)Nz{}:{:#x}Ú__main__zcelery.loadersé   ú (ú)z{min=z, max=ú}ú.éÿÿÿÿÚONz/OFF (enable -E to monitor tasks in this worker)r   )ÚmicrosecondF)ÚindentÚindent_first)
rG   rH   Ú	timestampÚversionÚconninfoÚresultsÚconcurrencyÚplatformÚeventsÚqueuesr“   z                r8   )#rG   ro   rÄ   r³   ÚmainÚidrn   Úloaderr   r   r-   Ú	autoscaleÚpool_clsÚ
__module__ÚsplitÚtask_eventsÚBANNERr   rH   r   ÚnowÚreplacer	   r�   Úas_uriÚbackendÚ	_platformrÅ   ÚamqprÇ   Ú
splitlinesr)   r€   ÚARTLINESÚ
IndexError)rL   ry   rG   rÄ   ÚapprrÊ   ÚmaxÚminÚpoolrÆ   ÚbannerÚiÚ_s                r0   r‚   zWorker.startup_infoø   s  € Ø�h‰hˆÜ˜$×*Ñ*Ó+ˆØ× Ñ  §¡Ò!7¨Z¼¸C»ÓAˆÜ˜#Ÿ*™*¤iÔ0Ü˜cŸj™jÓ)ˆFØ× Ñ Ð!1Ô2Ø  ˜�Ø�b˜˜ �NÑ"ˆDØ�>Š>Ø—~‘~‰HˆC�Ø" 3 % v¨c¨U°"Ð5ˆKØ�}‰}ˆÜ˜$¤Ô$Ø—?‘?ˆDØ˜˜DŸJ™J s›O¨BÑ/Ð0°Ð2Ñ2ˆØˆØ×ÒØFˆFä—‘ØÜ˜dŸm™mÓ,Ü—l‘l“n×,Ñ,¸Ð,Ó;Ü"Ø—X‘X×(Ñ(Ó*×1Ñ1Ó3Ø—H‘H×$Ñ$×+Ñ+Ó-Ø#Üœi×0Ñ0Ó2Ó3ØØ—8‘8—?‘?×)Ñ)°ÀÐ)ÓGð ó 
÷ ‰*‹,ð 	ñ Ü! &Ó)ò 5‘��1ð5Ø #§¡¬(°1©+°v¸a±yÐ)AÓ B�F˜1’Ið5ð
 �y‰y˜Ó  4Ñ'Ð'øô "ò 5Ø (¨6°!©9Ñ 4�F˜1“Ið5ús   È IÉIÉIc                 ó,  — | j                   j                  r| j                  «        | j                  s-| j                   j                  rt	        |«       nt        |«       t        |«       t        |«       t        |«       t        «        t        «        y)z1Install platform specific tweaks and workarounds.N)rG   ÚIS_macOSÚ macOS_proxy_detection_workaroundrZ   Ú!install_HUP_not_supported_handlerÚinstall_worker_restart_handlerÚinstall_worker_term_handlerÚ install_worker_term_hard_handlerÚinstall_worker_int_handlerÚinstall_cry_handlerÚinstall_rdb_handler)rL   Úworkers     r0   rl   zWorker.install_platform_tweaks"  si   € à�8‰8×ÒØ×1Ñ1Ô3ð �|Š|ð �x‰x× Ò ô 2°&Õ9ä.¨vÔ6Ü# FÔ+Ü(¨Ô0Ü" 6Ô*ÜÔÜÕr5   c                 óD   — t         j                  j                  dd«       y)z6See https://github.com/celery/celery/issues#issue/161.Úcelery_dummy_proxyÚset_by_celerydN)ÚosÚenvironÚ
setdefaultrc   s    r0   rã   z'Worker.macOS_proxy_detection_workaround8  s   € ä
�
‰
×ÑÐ2Ð4DÕEr5   c                 ó”   — t        j                  d|› dt        j                  t        j                  «      › d�| j
                  ¬«      S )NÚcelerydr·   r¸   )r‰   rH   )r   Úset_mp_process_titleÚstrargvrX   ÚargvrH   )rL   r‰   s     r0   rk   zWorker.set_process_status<  s?   € Ü×-Ñ-ØØ�6˜œI×-Ñ-¬c¯h©hÓ7Ð8¸Ð:Ø—]‘]ô
ð 	
r5   )F)FNNNr`   )Tr8   zcelery.)T)Ú__name__rÍ   Ú__qualname__Ú__doc__rN   r^   rd   rg   rj   r‹   ra   rŸ   ri   r­   r„   r‚   rl   rã   rk   Ú__classcell__)rv   s   @r0   r   r   d   s^   ø„ Ùó
7ð 37ØDHó
òBô&òP
.ò:ó
ò
ò6ló
ò9ó((òTò,Fö
r5   r   ÚSIGTERMÚWarmTrë   c                 óp   ‡ ‡‡‡‡‡— ˆˆˆˆˆˆ fd„}t        d‰› �«      |_        |t        j                  ‰<   y)a<  Install signal handler for warm/cold shutdown.

    The handler will run from the MainProcess.

    Args:
        worker (Worker): The worker that received the signal.
        sig (str, optional): The signal that was received. Defaults to 'TERM'.
        how (str, optional): The type of shutdown to perform. Defaults to 'Warm'.
        callback (Callable, optional): Signal handler. Defaults to None.
        exitcode (int, optional): The exit code to use. Defaults to EX_OK.
        verbose (bool, optional): Whether to print the type of shutdown. Defaults to True.
    c            	      ó†  •— t        «       5  ddlm} 	 t        «       j                  dk(  rW‰r ‰‰«       ‰rt        d‰› d�t        j                  «       t        j                  j                  ‰j                  ‰‰‰¬«       t        |ddd	œ‰   ‰«       	 d d d «       y # t        |ddd	œ‰   ‰«       w xY w# 1 sw Y   y xY w)
Nr   ©ÚstateÚMainProcesszworker: z shutdown (MainProcess))rA   ÚsigÚhowÚexitcodeÚshould_stopÚshould_terminate)rü   ÚCold)r   Úcelery.workerr   r   Ú_namer>   rX   r…   r   Úworker_shutting_downrJ   rH   Úsetattr)Úargsr   Úcallbackr  r  r  Úverboserë   s     €€€€€€r0   Ú_handle_requestz*_shutdown_handler.<locals>._handle_requestQ  sÖ   ø€ Ü‹_ñ 	LÝ+ðLÜ"Ó$×*Ñ*¨mÒ;ÙÙ  Ô(ÙÜ  8¨C¨5Ð0GÐ!HÌ#Ï.É.ÔYÜ×0Ñ0×5Ñ5Ø%Ÿ™°C¸SØ!)ð 6ô ô ˜¨Ø(:ñ <Ø<?ñ AØBJõL÷-	Lð 	Løô, ˜¨Ø(:ñ <Ø<?ñ AØBJõLú÷-	Lð 	Lús#   ŒB7”A.BÂB7ÂB4Â4B7Â7C Úworker_N)ro   r÷   r   r   )rë   r  r  r  r  r  r  s   `````` r0   Ú_shutdown_handlerr  D  s4   ý€ ÷Lñ Lô2  # W¨S¨E ?Ó3€OÔØ,„I×Ñ�cÒr5   c                 ó&   — ddl m}  |t        «      ‚)au  Signal handler for hard shutdown.

    The handler will terminate the worker immediately by force using the exit code ``EX_FAILURE``.

    In practice, you should never get here, as the standard shutdown process should be enough.
    This handler is only for the worst-case scenario, where the worker is stuck and cannot be
    terminated gracefully (e.g., spamming the Ctrl+C in the terminal to force the worker to terminate).

    Args:
        worker (Worker): The worker that received the signal.

    Raises:
        WorkerTerminate: This exception will be raised in the MainProcess to terminate the worker immediately.
    r   )ÚWorkerTerminate)Úcelery.exceptionsr  r   )rë   r  s     r0   Úon_hard_shutdownr  n  s   € õ 2Ù
œ*Ó
%Ð%r5   c                 ó¶   — t        | dt        d¬«       t        | dt        ¬«       | j                  j                  «        t	        dt
        j                  «       y)am  This signal handler is called when the worker is in the middle of the soft shutdown process.

    When the worker is in the soft shutdown process, it is waiting for tasks to finish. If the worker
    receives a SIGINT (Ctrl+C) or SIGQUIT signal (or possibly SIGTERM if REMAP_SIGTERM is set to "SIGQUIT"),
    the handler will cancels all unacked requests to allow the worker to terminate gracefully and replace the
    signal handler for SIGINT and SIGQUIT with the hard shutdown handler ``on_hard_shutdown`` to terminate
    the worker immediately by force next time the signal is received.

    It will give the worker once last chance to gracefully terminate (the cold shutdown), after canceling all
    unacked requests, before using the hard shutdown handler to terminate the worker forcefully.

    Args:
        worker (Worker): The worker that received the signal.
    ÚSIGINTF)r  r  r  ÚSIGQUIT©r  r  z3Waiting gracefully for cold shutdown to complete...N)rç   r  rŠ   Úcancel_active_requestsr>   rX   r…   ©rë   s    r0   Úduring_soft_shutdownr  �  sD   € ô" % V°ÔDTÐ^cÕdÜ$ V°ÔEUÕVð ‡O�O×*Ñ*Ô,ô ÐBÄCÇNÁNÕSr5   c                 ó€  — t        dt        j                  «       t        | dt        ¬«       t        | dt        ¬«       t
        dk(  rt        | dt        ¬«       | j                  «        t        | j                  dd«      }|�t        |t        «       | j                  j                  r4t        | j                  | j                  j                  j                  «       | j                  j                  «        dd	lm} d
|_        | j                  j$                  r%| j                  j$                  j'                  «        yy)aZ	  Signal handler for cold shutdown.

    Registered for SIGQUIT and SIGINT (Ctrl+C) signals. If REMAP_SIGTERM is set to "SIGQUIT", this handler will also
    be registered for SIGTERM.

    This handler will initiate the cold (and soft if enabled) shutdown procesdure for the worker.

    Worker running with N tasks:
        - SIGTERM:
            -The worker will initiate the warm shutdown process until all tasks are finished. Additional.
            SIGTERM signals will be ignored. SIGQUIT will transition to the cold shutdown process described below.
        - SIGQUIT:
            - The worker will initiate the cold shutdown process.
            - If the soft shutdown is enabled, the worker will wait for the tasks to finish up to the soft
            shutdown timeout (practically having a limited warm shutdown just before the cold shutdown).
            - Cancel all tasks (from the MainProcess) and allow the worker to complete the cold shutdown
            process gracefully.

    Caveats:
        - SIGINT (Ctrl+C) signal is defined to replace itself with the cold shutdown (SIGQUIT) after first use,
        and to emit a message to the user to hit Ctrl+C again to initiate the cold shutdown process. But, most
        important, it will also be caught in WorkController.start() to initiate the warm shutdown process.
        - SIGTERM will also be handled in WorkController.start() to initiate the warm shutdown process (the same).
        - If REMAP_SIGTERM is set to "SIGQUIT", the SIGTERM signal will be remapped to SIGQUIT, and the cold
        shutdown process will be initiated instead of the warm shutdown process using SIGTERM.
        - If SIGQUIT is received (also via SIGINT) during the cold/soft shutdown process, the handler will cancel all
        unacked requests but still wait for the soft shutdown process to finish before terminating the worker
        gracefully. The next time the signal is received though, the worker will terminate immediately by force.

    So, the purpose of this handler is to allow waiting for the soft shutdown timeout, then cancel all tasks from
    the MainProcess and let the WorkController.terminate() to terminate the worker naturally. If the soft shutdown
    is disabled, it will immediately cancel all tasks let the cold shutdown finish normally.

    Args:
        worker (Worker): The worker that received the signal.
    z>worker: Hitting Ctrl+C again will terminate all running tasks!r  r  r  rû   r�   Nr   rÿ   T)r>   rX   r…   rç   r  r   Úwait_for_soft_shutdownÚgetattrrŠ   r   r   Útask_consumerr   Úcancelr  r  r   r  rÝ   Ústop)rë   r�   r   s      r0   Úon_cold_shutdownr#     sì   € ôJ ÐMÌsÏ~É~Ô^ô % V°ÔDXÕYÜ$ V°ÔEYÕZÜ˜	Ò!Ü(¨°YÔI]Õ^ð ×!Ñ!Ô#ô ˜Ÿ™¨,¸Ó=€JØÐÜ! *Ô.EÔFð ‡�×$Ò$Ü�f—o‘o v§¡×'DÑ'D×'KÑ'KÔLð ‡O�O×*Ñ*Ô,å#Ø!€EÔð ‡�×ÒØ�‰×Ñ×!Ñ!Õ#ð r5   r  r  )r  r  r  r  )r  r  c                   ó   — y r`   © )ÚaÚkws     r0   ú<lambda>r(  ú  s   � r5   c                 óT   — t        dt        j                  «       t        | dd¬«       y )NzXworker: Hitting Ctrl+C again will initiate cold shutdown, terminating all running tasks!r  F)r  r  )r>   rX   r…   rç   r  s    r0   Ú	on_SIGINTr*  ý  s    € ÜÐgÜ�^‰^ôä$ V°À5ÖIr5   r  )r  r  r  c                   ó   — y r`   r%  )r  rM   s     r0   rè   rè   	  s   € Ør5   c                  ó  — t        j                  t        j                  t        j                  t        j
                  g«       t        j                  t        j                  t        j                  gt        j                  z   «       y r`   )
r   Úclose_open_fdsrX   Ú	__stdin__r…   Ú
__stderr__rï   ÚexecvÚ
executablerö   r%  r5   r0   Ú_reload_current_workerr2    sL   € Ü×ÑÜ�‰”s—~‘~¤s§~¡~ðô ô ‡H�HŒS�^‰^œcŸn™nÐ-´·±Ñ8Õ9r5   c                 ó0   — d„ }|t         j                  |<   y )Nc                  óä   — t        d«       t        ddj                  t        j                  «      › d�t        j
                  «       ddl}|j                  t        «       ddl	m
} t        |_        y)z5Signal handler restarting the current python program.TzRestarting celery worker (r“   r¸   r   Nrÿ   )r   r>   r€   rX   rö   r…   ÚatexitÚregisterr2  r  r   r   r  )r  r5  r   s      r0   Úrestart_worker_sig_handlerzBinstall_worker_restart_handler.<locals>.restart_worker_sig_handler  sN   € ä˜$ÔÜÐ-¨c¯h©h´s·x±xÓ.@Ð-AÀÐCÜ—‘ô	!ãØ�‰Ô.Ô/Ý'Ü!ˆÕr5   ©r   r   )rë   r  r7  s      r0   rå   rå     s   € ò"ð 8„I×Ñ�cÒr5   c                 ó>   — t         ry d„ }|t        j                  | <   y )Nc                  óh   — t        «       5  t        t        «       «       ddd«       y# 1 sw Y   yxY w)z=Signal handler logging the stack-trace of all active threads.N)r   r>   r   )r  s    r0   Úcry_handlerz(install_cry_handler.<locals>.cry_handler'  s%   € ä‹_ñ 	Ü”S“UŒO÷	÷ 	ñ 	ús   ‹(¨1)Úis_pypyr   r   )r  r;  s     r0   ré   ré   "  s   € åØòð )„I×Ñ�cÒr5   c                 óp   — d„ }t         j                  j                  | «      r|t        j                  |<   y y )Nc                  ó’   — t        «       5  ddlm}m} | r| d   n |«       j                  } ||«       ddd«       y# 1 sw Y   yxY w)z=Signal handler setting a rdb breakpoint at the current frame.r   )Ú_frameÚ	set_tracer+   N)r   Úcelery.contrib.rdbr?  r@  Úf_back)r  r?  r@  Úframes       r0   Úrdb_handlerz(install_rdb_handler.<locals>.rdb_handler1  s<   € ä‹_ñ 	ß<ñ  $�D˜’G©«¯©ˆEÙ�eÔ÷	÷ 	ñ 	ús	   ‹)=½A)rï   rð   Úgetr   r   )Úenvvarr  rD  s      r0   rê   rê   .  s.   € òô 
‡z�z‡~�~�fÔØ!,Œ	×Ñ˜#Òð r5   c                 ó6   ‡— ˆfd„}|t         j                  ‰<   y )Nc                 óz   •— t        «       5  t        dj                  ‰¬«      «       d d d «       y # 1 sw Y   y xY w)NzH{sig} not supported: Restarting with {sig} is unstable on this platform!)r  )r   r>   r³   )ÚsignumrC  r  s     €r0   Úwarn_on_HUP_handlerz>install_HUP_not_supported_handler.<locals>.warn_on_HUP_handler?  s:   ø€ Ü‹_ñ 	CÜð 2ß28±&¸S°&³/ôC÷	C÷ 	Cñ 	Cús   Œ1±:r8  )rë   r  rJ  s    ` r0   rä   rä   =  s   ø€ ôCð 1„I×Ñ�cÒr5   )ÚSIGHUP)ÚSIGUSR1)ÚCELERY_RDBSIGÚSIGUSR2)Orù   r¯   rï   rÅ   rÕ   rX   r   Ú	functoolsr   Úbilliard.commonr   Úbilliard.processr   Úkombu.commonr   Úkombu.utils.encodingr   Úceleryr	   r
   r   r   Ú
celery.appr   Úcelery.loaders.appr   Úcelery.platformsr   r   r   r   Úcelery.utilsr   r   Úcelery.utils.debugr   Úcelery.utils.importsr   Úcelery.utils.logr   r   r   Úcelery.utils.textr   Úcelery.utils.threadsr   Úcelery.utils.timer   r  r   Úcelery.worker.workerr   Ú__all__r÷   rr   r-   Ú	is_jythonr9   r<  rØ   rÐ   r²   r4   r/  r>   r   r  r  r  r#  ræ   rç   r*  rè   r2  rå   ré   rê   rä   r%  r5   r0   ú<module>rb     s±  ðñó Û 	Û Û 
Ý Ý å )Ý ,Ý &Ý )ç IÓ IÝ Ý (ß HÓ Hß %Ý "Ý )ß IÑ IÝ 'Ý :Ý .Ý (Ý 8à
€á	�HÓ	€Ø�L‰L×#Ñ# FÓ+€	Ù
�#Ð*Ó
+€ò€ð
€ð €ò3ð —N‘Nó ô ]
ˆ^ô ]
ð@ +4¸È$ÐY^Ðhlñ '-˜fó '-ðT&˜Vó &ð&T ó Tð>F$˜Vó F$ðT �IÒÙ")Ø˜y¨fÐ?OÐZdô#Ññ #*Ø˜y¨fô#Ðñ
 Ù'.Ø˜y¨fÐ?OÐZdô(Ñ$ñ
 ,AðAÐØ(òJñ Ù!(Ø˜x°)Øô"Ñò
ò:ó8ó	)ð  /Ø%ó-ô1r5   