a
    ƹDfr                     @   s   d Z G dd deZdS )zq
This module implements a selector class, which can be used to dispatch
events and for event handler wrangling.

c                   @   s   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZddlmZ edddZ[dZdS )Selectorz:
Selector object for watching and event notification.
    Nc                 C   s`   |r
|| _ |   dS z|   W n8   |   ddl}| dd \}}||Y n0 dS )z*dispatch events to the registered hanldersN       )_timeout_watch_cleanupsysexc_info)selftimeoutr   typevalue r   \/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/selector.pywatch   s    zSelector.watchc                 C   s   | j |g | dS )zEadd <handler> to the list of routines to call when <fd> is read readyN)_input
setdefaultappendr	   fdhandlerr   r   r   notifyOnReadReady=   s    zSelector.notifyOnReadReadyc                 C   s   | j |g | dS )zFadd <handler> to the list of routines to call when <fd> is write readyN)_outputr   r   r   r   r   r   notifyOnWriteReadyC   s    zSelector.notifyOnWriteReadyc                 C   s   | j |g | dS )zKadd <handler> to the list of routines to call when <fd> raises an exceptionN)
_exceptionr   r   r   r   r   r   notifyOnExceptionI   s    zSelector.notifyOnExceptionc                 C   s   | j | dS )zCadd <handler> to the list of routines to call when a signal arrivesN)
_interruptr   r	   r   r   r   r   notifyOnInterruptO   s    zSelector.notifyOnInterruptc                 C   s   | j | dS )zCadd <handler> to the list of routines to call when a timeout occursN)_idler   r   r   r   r   notifyWhenIdleU   s    zSelector.notifyWhenIdlec                 C   s0   d| _ | j| _i | _i | _i | _g | _g | _dS )z!
Takes no initial input.
        TN)state_TIMEOUTr   r   r   r   r   r   )r	   r   r   r   __init__[   s    zSelector.__init__c              
   C   s  dd l }| jr| jd t| j }t| j }t| j }| jd|  | jd|  | jd|  | jd |s|s|s| j	s| j
d d S | jd z| |||| j\}}}W nR |jy } z6|j\}	}
| j
d	|	|
f  W Y d }~qW Y d }~n
d }~0 0 | jd
 |sp|sp|sp| j
d | j	D ]}|| sP| j	| qPq| j
d | | j| | j
d | | j| | j
d | | j| qd S )Nr   zconstructing list of watchersz	input: %sz
output: %szexception: %szchecking for indefinite blockz$no registered handlers left; exitingzcalling selectzsignal received: %d: %szreturned from selectz)no activity; dispatching to idle handlersz!dispatching to exception handlerszdispatching to output handlerszdispatching to input handlers)selectr    _debugdebuglistr   keysr   r   r   infor   errorargsremove	_dispatch)r	   r#   ZiwtdZowtdZewtdZreadsZwritesZexceptsr)   errnomsgr   r   r   r   r   n   sB    
"

zSelector._watchc                 C   sB   |D ]8}|| D ]}|| |s||  | q|| s||= qd S )N)r+   )r	   handlersentitiesr   r   r   r   r   r,      s    
zSelector._dispatchc                 C   s`   | j d | jD ]}|  q| jD ]}|  q&| jD ]}|  q:| jD ]}||  qNd S )Nzcleaning up)r$   r(   r   closer   r   r   r   r   r   r   r      s    







zSelector._cleanupr   )loggerzpathos.selector   )namelevelg      ?)N)__name__
__module____qualname____doc__r   r   r   r   r   r   r"   r   r,   r   Zpathosr2   r$   r!   r   r   r   r   r      s   
3r   N)r9   objectr   r   r   r   r   <module>   s   