o
    º­§i{
  ã                   @   sl   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„ deƒZ
G dd„ de
ƒZG d	d
„ d
e
ƒZdS )é    N)Úabstractmethod)ÚBrokenProcessPool)ÚBaseExecutorÚrun_jobc                       s2   e Zd Ze‡ fdd„ƒZdd„ Zddd„Z‡  ZS )	ÚBasePoolExecutorc                    s   t ƒ  ¡  || _d S ©N)ÚsuperÚ__init__Ú_pool)ÚselfÚpool©Ú	__class__© úQ/home/app/Keep/.python/lib/python3.10/site-packages/apscheduler/executors/pool.pyr	   
   s   

zBasePoolExecutor.__init__c                    s6   ‡ ‡fdd„}ˆj  tˆ ˆ j|ˆjj¡}| |¡ d S )Nc                    s\   t | dƒr	|  ¡ n|  ¡ t|  ¡ dd ƒf\}}|r#ˆ ˆ j||¡ d S ˆ ˆ j|  ¡ ¡ d S )NÚexception_infoÚ__traceback__)Úhasattrr   Ú	exceptionÚgetattrZ_run_job_errorÚidZ_run_job_successÚresult)ÚfÚexcÚtb©Újobr   r   r   Úcallback   s   
ÿýz1BasePoolExecutor._do_submit_job.<locals>.callback)r
   Úsubmitr   Z_jobstore_aliasÚ_loggerÚnameÚadd_done_callback)r   r   Ú	run_timesr   r   r   r   r   Ú_do_submit_job   s
   ÿzBasePoolExecutor._do_submit_jobTc                 C   s   | j  |¡ d S r   )r
   Úshutdown)r   Úwaitr   r   r   r$       s   zBasePoolExecutor.shutdown)T)Ú__name__Ú
__module__Ú__qualname__r   r	   r#   r$   Ú__classcell__r   r   r   r   r   	   s
    r   c                       s"   e Zd ZdZd‡ fdd„	Z‡  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                    s0   |pi }t jjt|ƒfi |¤Ž}tƒ  |¡ d S r   )Ú
concurrentÚfuturesr*   Úintr   r	   ©r   Úmax_workersÚpool_kwargsr   r   r   r   r	   /   s   zThreadPoolExecutor.__init__©r+   N)r&   r'   r(   Ú__doc__r	   r)   r   r   r   r   r*   $   s    
r*   c                       s.   e Zd ZdZd‡ fdd„	Z‡ fdd„Z‡  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
    r+   Nc                    sH   |pi | _ | j  dt d¡¡ tjjt|ƒfi | j ¤Ž}tƒ  	|¡ d S )NZ
mp_contextZspawn)
r1   Ú
setdefaultÚmultiprocessingZget_contextr,   r-   r4   r.   r   r	   r/   r   r   r   r	   @   s   
ÿÿzProcessPoolExecutor.__init__c                    s`   z
t ƒ  ||¡ W d S  ty/   | j d¡ | jj| jjfi | j¤Ž| _t ƒ  ||¡ Y d S w )Nz<Process pool is broken; replacing pool with a fresh instance)	r   r#   r   r   Úwarningr
   r   Z_max_workersr1   )r   r   r"   r   r   r   r#   H   s   ÿÿÿùz"ProcessPoolExecutor._do_submit_jobr2   )r&   r'   r(   r3   r	   r#   r)   r   r   r   r   r4   5   s    
r4   )Úconcurrent.futuresr,   r6   Úabcr   Úconcurrent.futures.processr   Zapscheduler.executors.baser   r   r   r*   r4   r   r   r   r   Ú<module>   s    