B
     \                 @   sZ   d Z ddlmZmZmZ ddlZG dd deZG dd deZdd	 Z	e
d
krVe	  dS )zj
Implement background services for the application.
This is implemented as a cooperative concurrent task.
    )absolute_importprint_functiondivisionNc               @   s>   e Zd ZdddZdd Zdd Zd	d
 Zdd Zdd ZdS )ServiceunnamedNc             C   s.   || _ d| _|| _| | j| _t| j d S )NT)nameenabledargprocess_tasknext)selfr   r	    r   7lib/python3.7/site-packages/numba/servicelib/service.py__init__   s
    zService.__init__c             C   s.   | j r*| j }zd| _ t| j W d|| _ X dS )z
        Request for the service task.
        Servicing is disabled if it is disabled thourght the "enabled"
        attribute.  When the task is executing, the service is disabled to
        avoid recursion.
        FN)r   r   r   )r   enabler   r   r   service   s    zService.servicec             C   s   t dS )z
        Overrided to implement the service task.
        This must be a generator.
        Use `yield` to return control.
        N)NotImplementedError)r   r	   r   r   r   r
   "   s    zService.processc             C   s   | S )Nr   )r   r   r   r   	__enter__*   s    zService.__enter__c             C   s   |    d S )N)r   )r   exc_typeZexc_valZexc_tbr   r   r   __exit__-   s    zService.__exit__c                s   t   fdd}|S )zM
        A decorator for a function. Service is triggered on return.
        c           	      s     | |S Q R X d S )Nr   )argsZkws)fnr   r   r   wrap4   s    zService.after.<locals>.wrap)	functoolswraps)r   r   r   r   )r   r   r   after0   s    zService.after)r   N)	__name__
__module____qualname__r   r   r
   r   r   r   r   r   r   r   r   
   s   
r   c               @   s   e Zd Zdd ZdS )HelloServicec             c   s,   d}d V  xt d| |d7 }d V  qW d S )Nr   ZHello   )print)r   r	   countr   r   r   r
   ?   s    
zHelloService.processN)r   r   r   r
   r   r   r   r   r    >   s   r    c           	   C   sX   t d} td |   td |   |  td W d Q R X | jdd }|  d S )Nzmy.hello123c               S   s   t d d S )N4)r"   r   r   r   r   nestedQ   s    ztest.<locals>.nested)r    r"   r   r   )Zservr(   r   r   r   testG   s    r)   __main__)__doc__Z
__future__r   r   r   r   objectr   r    r)   r   r   r   r   r   <module>   s   4	