
    i{
                         d dl Zd dlZd dlmZ d dlmZ d dlmZm	Z	  G d de          Z
 G d de
          Z G d	 d
e
          ZdS )    N)abstractmethod)BrokenProcessPool)BaseExecutorrun_jobc                   <     e Zd Ze fd            Zd ZddZ xZS )BasePoolExecutorc                 V    t                                                       || _        d S N)super__init___pool)selfpool	__class__s     a/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/apscheduler/executors/pool.pyr   zBasePoolExecutor.__init__
   s$    


    c                       fd} j                             t          j        | j        j                  }|                    |           d S )Nc                 ^   t          | d          r|                                 n6|                                 t          |                                 dd           f\  }}|r                    j        ||           d S                     j        |                                            d S )Nexception_info__traceback__)hasattrr   	exceptiongetattr_run_job_errorid_run_job_successresult)fexctbjobr   s      r   callbackz1BasePoolExecutor._do_submit_job.<locals>.callback   s     1.//T  """kkmmWQ[[]]OT%R%RS C
  :##CFC44444%%cfahhjj99999r   )r   submitr   _jobstore_alias_loggernameadd_done_callback)r   r!   	run_timesr"   r   s   ``   r   _do_submit_jobzBasePoolExecutor._do_submit_job   sj    		: 		: 		: 		: 		: 		: JS#-y$,:K
 
 	
H%%%%%r   Tc                 :    | j                             |           d S r
   )r   shutdown)r   waits     r   r+   zBasePoolExecutor.shutdown    s    
D!!!!!r   )T)__name__
__module____qualname__r   r   r)   r+   __classcell__r   s   @r   r   r   	   se            ^& & &"" " " " " " " "r   r   c                   $     e Zd ZdZd fd	Z xZS )ThreadPoolExecutora  
    An executor that runs jobs in a concurrent.futures thread pool.

    Plugin alias: ``threadpool``

    :param max_workers: the maximum number of spawned threads.
    :param pool_kwargs: dict of keyword arguments to pass to the underlying
        ThreadPoolExecutor constructor
    
   Nc                     |pi }t          j        j        t          |          fi |}t	                                          |           d S r
   )
concurrentfuturesr3   intr   r   r   max_workerspool_kwargsr   r   s       r   r   zThreadPoolExecutor.__init__/   sN    !'R!4S5E5EUUUUr   r4   N)r-   r.   r/   __doc__r   r0   r1   s   @r   r3   r3   $   sG                  r   r3   c                   .     e Zd ZdZd fd	Z fdZ xZS )ProcessPoolExecutora#  
    An executor that runs jobs in a concurrent.futures process pool.

    Plugin alias: ``processpool``

    :param max_workers: the maximum number of spawned processes.
    :param pool_kwargs: dict of keyword arguments to pass to the underlying
        ProcessPoolExecutor constructor
    r4   Nc                    |pi | _         | j                             dt          j        d                     t	          j        j        t          |          fi | j         }t                      	                    |           d S )N
mp_contextspawn)
r;   
setdefaultmultiprocessingget_contextr6   r7   r?   r8   r   r   r9   s       r   r   zProcessPoolExecutor.__init__@   s    &,"##L/2Mg2V2VWWW!5
 
 $ 0
 
 	r   c                 6   	 t                                          ||           d S # t          $ rg | j                            d            | j        j        | j        j        fi | j        | _        t                                          ||           Y d S w xY w)Nz<Process pool is broken; replacing pool with a fresh instance)	r   r)   r   r%   warningr   r   _max_workersr;   )r   r!   r(   r   s      r   r)   z"ProcessPoolExecutor._do_submit_jobH   s    		3GG""3	22222  	3 	3 	3L  N   .-
' +/+; DJ GG""3	222222	3s   "' A-BBr<   )r-   r.   r/   r=   r   r)   r0   r1   s   @r   r?   r?   5   s`              
3 
3 
3 
3 
3 
3 
3 
3 
3r   r?   )concurrent.futuresr6   rD   abcr   concurrent.futures.processr   apscheduler.executors.baser   r   r   r3   r?    r   r   <module>rN      s                  8 8 8 8 8 8 < < < < < < < <" " " " "| " " "6    )   "3 3 3 3 3* 3 3 3 3 3r   