o
    JXh                     @   s   	 d dl Z d dlZd dlmZmZmZmZ g dZddddZdd	 Z	d
d Z
dd ZG dd dZdd Zdd ZG dd dZe ZG dd deZG dd deZdS )    N)ChannelErrorChannelNotFoundErrorChannelEmptyErroris_shareable)Interpreterget_currentget_maincreatelist_allSendChannelRecvChannelcreate_channellist_all_channelsr   r   r   r   Tisolatedc                 C   s   	 t j| d}t|| dS )Nr   )_interpretersr	   r   )r   id r   C/opt/python-3.10.19/usr/lib/python3.10/test/support/interpreters.pyr	      s   r	   c                   C      	 dd t  D S )Nc                 S   s   g | ]}t |qS r   )r   ).0r   r   r   r   
<listcomp>   s    zlist_all.<locals>.<listcomp>)r   r
   r   r   r   r   r
      s   r
   c                  C      	 t  } t| S N)r   r   r   r   r   r   r   r   !      r   c                  C   r   r   )r   r   r   r   r   r   r   r   '   r   r   c                   @   sj   e Zd Z	 ddddZdd Zdd Zd	d
 Zedd Zedd Z	dd Z
dd ZddddZdS )r   Nr   c                C   s.   t |ttjfstd||| _|| _d S Nzid must be an int, got )
isinstanceintr   ZInterpreterID	TypeError_id	_isolated)selfr   r   r   r   r   __init__0   s   
zInterpreter.__init__c                 C   sB   t t| j| jd}dd | D }t| j dd| dS )N)r   r   c                 s   s"    | ]\}}| d |V  qdS )=Nr   )r   kvr   r   r   	<genexpr>8   s     z'Interpreter.__repr__.<locals>.<genexpr>(z, ))dictr   r    r!   itemstype__name__join)r"   datakwargsr   r   r   __repr__6   s   zInterpreter.__repr__c                 C   
   t | jS r   hashr    r"   r   r   r   __hash__;      
zInterpreter.__hash__c                 C   s   t |tstS |j| jkS r   )r   r   NotImplementedr    r"   otherr   r   r   __eq__>   s   
zInterpreter.__eq__c                 C      | j S r   r    r5   r   r   r   r   D      zInterpreter.idc                 C   s   | j d u rt| j| _ | j S r   )r!   r   Zis_isolatedr    r5   r   r   r   r   H   s   
zInterpreter.isolatedc                 C      	 t | jS r   )r   
is_runningr    r5   r   r   r   r@   P   s   zInterpreter.is_runningc                 C   r?   r   )r   Zdestroyr    r5   r   r   r   closeT   s   zInterpreter.close)channelsc               C   s   	 t | j|| d S r   )r   Z
run_stringr    )r"   Zsrc_strrB   r   r   r   run\   s   zInterpreter.run)r-   
__module____qualname__r#   r1   r6   r;   propertyr   r   r@   rA   rC   r   r   r   r   r   -   s    

r   c                  C   s$   	 t  } t| t| }}||fS r   )r   Zchannel_creater   r   )cidrecvsendr   r   r   r   d   s   r   c                   C   r   )Nc                 S   s   g | ]
}t |t|fqS r   )r   r   )r   rG   r   r   r   r   p   s    z%list_all_channels.<locals>.<listcomp>)r   Zchannel_list_allr   r   r   r   r   n   s   r   c                   @   s:   e Zd Z	 dd Zdd Zdd Zdd Zed	d
 ZdS )_ChannelEndc                 C   s(   t |ttjfstd||| _d S r   )r   r   r   Z	ChannelIDr   r    )r"   r   r   r   r   r#   w   s   
z_ChannelEnd.__init__c                 C   s   t | j dt| j dS )Nz(id=r)   )r,   r-   r   r    r5   r   r   r   r1   |   s   z_ChannelEnd.__repr__c                 C   r2   r   r3   r5   r   r   r   r6      r7   z_ChannelEnd.__hash__c                 C   s4   t | trt |tstS nt |tstS |j| jkS r   )r   r   r8   r   r    r9   r   r   r   r;      s   


z_ChannelEnd.__eq__c                 C   r<   r   r=   r5   r   r   r   r      r>   z_ChannelEnd.idN)	r-   rD   rE   r#   r1   r6   r;   rF   r   r   r   r   r   rJ   t   s    rJ   c                   @   s,   e Zd Z	 e ddddZefddZdS )r   g{Gz?)	_sentinel_delayc                C   s<   	 t | j|}||u rt| t | j|}||u s|S r   )r   channel_recvr    timesleep)r"   rK   rL   objr   r   r   rH      s   
zRecvChannel.recvc                 C   s$   	 |t u rt| jS t| j|S r   )_NOT_SETr   rM   r    )r"   defaultr   r   r   recv_nowait   s   zRecvChannel.recv_nowaitN)r-   rD   rE   objectrH   rQ   rS   r   r   r   r   r      s    r   c                   @   s   e Zd Z	 dd Zdd ZdS )r   c                 C   s   	 t | j| td d S )N   )r   channel_sendr    rN   rO   r"   rP   r   r   r   rI      s   zSendChannel.sendc                 C   s   	 t | j|S r   )r   rV   r    rW   r   r   r   send_nowait   s   zSendChannel.send_nowaitN)r-   rD   rE   rI   rX   r   r   r   r   r      s    r   )rN   Z_xxsubinterpretersr   r   r   r   r   __all__r	   r
   r   r   r   r   r   rJ   rT   rQ   r   r   r   r   r   r   <module>   s     	7
