U
    “öhô  ã                   @   sŠ   d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 zd dl
mZ d dlmZ W n ek
rt   dd	„ ZY nX G d
d„ deƒZdS )é    )Úabsolute_importN)ÚThreadPoolExecutor)Úconvert_yielded)ÚBaseExecutorÚrun_job)Úrun_coroutine_job)Úiscoroutinefunction_partialc                 C   s   dS )NF© )Úfuncr	   r	   úA/tmp/pip-unpacked-wheel-ehb4gh6l/apscheduler/executors/tornado.pyr      s    r   c                       s6   e Zd ZdZd	‡ fdd„	Z‡ fdd„Zdd„ Z‡  ZS )
ÚTornadoExecutorak  
    Runs jobs either in a thread pool or directly on the I/O loop.

    If the job function is a native coroutine function, it is scheduled to be run directly in the
    I/O loop as soon as possible. All other functions are run in a thread pool.

    Plugin alias: ``tornado``

    :param int max_workers: maximum number of worker threads in the thread pool
    é
   c                    s   t t| ƒ ¡  t|ƒ| _d S ©N)Úsuperr   Ú__init__r   Úexecutor)ÚselfÚmax_workers©Ú	__class__r	   r   r      s    zTornadoExecutor.__init__c                    s   t t| ƒ ||¡ |j| _d S r   )r   r   ÚstartZ_ioloop)r   Z	schedulerÚaliasr   r	   r   r   "   s    zTornadoExecutor.startc                    s^   ‡ ‡fdd„}t ˆ jƒr.tˆ ˆ j|ˆjjƒ}nˆj tˆ ˆ j|ˆjj¡}t	|ƒ}| 
|¡ d S )Nc                    sR   z|   ¡ }W n2 tk
r>   ˆjˆ jft ¡ dd … žŽ  Y nX ˆ ˆ j|¡ d S )Né   )ÚresultÚBaseExceptionZ_run_job_errorÚidÚsysÚexc_infoZ_run_job_success)ÚfÚevents©Újobr   r	   r   Úcallback'   s
    $z0TornadoExecutor._do_submit_job.<locals>.callback)r   r
   r   Z_jobstore_aliasZ_loggerÚnamer   Zsubmitr   r   Zadd_done_callback)r   r!   Z	run_timesr"   r   r	   r    r   Ú_do_submit_job&   s    
ÿzTornadoExecutor._do_submit_job)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r$   Ú__classcell__r	   r	   r   r   r      s   r   )Ú
__future__r   r   Úconcurrent.futuresr   Ztornado.genr   Zapscheduler.executors.baser   r   Zapscheduler.executors.base_py3r   Zapscheduler.utilr   ÚImportErrorr   r	   r	   r	   r   Ú<module>   s   