o
    $i
                     @   sZ   d dl Z d dlmZmZ d dlmZ d dlmZ d dlm	Z	 e	ddG dd	 d	eZ
dS )
    N)AnyOptional)ChannelContext)ChannelInterface)	PublicAPIalpha)	stabilityc                   @   s   e Zd ZdZ	ddee fddZdddZdd	d
Zdd Z	defddZ
ddedee fddZddee dedefddZdddZdS )IntraProcessChannelaI  
    IntraProcessChannel is a channel for communication between two tasks in the same
    worker process. It writes data directly to the worker's _SerializationContext
    and reads data from the _SerializationContext to avoid the serialization
    overhead and the need for reading/writing from shared memory. Note that if the
    readers may mutate the data, users should deep copy the data themselves to avoid
    side effects.

    Args:
        num_readers: The number of readers that will read from this channel. Readers
            can be the same method of the same actor.
    N_channel_idc                 C   s,   || _ || _| j d u rtt | _ d S d S N)r
   _num_readersstruuiduuid4)selfnum_readersr
    r   k/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/experimental/channel/intra_process_channel.py__init__   s
   
zIntraProcessChannel.__init__returnc                 C      d S r   r   r   r   r   r   ensure_registered_as_writer$      z/IntraProcessChannel.ensure_registered_as_writerc                 C   r   r   r   r   r   r   r   ensure_registered_as_reader'   r   z/IntraProcessChannel.ensure_registered_as_readerc                 C   s   t | j| jffS r   )r	   r   r
   r   r   r   r   
__reduce__*   s   zIntraProcessChannel.__reduce__c                 C   s   d| j  dS )NzIntraProcessChannel(channel_id=))r
   r   r   r   r   __str__0   s   zIntraProcessChannel.__str__valuetimeoutc                 C   s(   |    t j}|| j|| j d S r   )r   r   get_currentserialization_contextset_datar
   r   )r   r   r   ctxr   r   r   write3   s   
zIntraProcessChannel.writeTdeserializec                 C   s*   |    |s
J dt j}|| jS )Nz8Data passed from the actor to itself is never serialized)r   r   r    r!   get_datar
   )r   r   r%   r#   r   r   r   read=   s   
zIntraProcessChannel.readc                 C   s   t  j}|| j d S r   )r   r    r!   
reset_datar
   )r   r#   r   r   r   closeD   s   
zIntraProcessChannel.closer   )r   N)NT)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   floatr$   boolr'   r)   r   r   r   r   r	   	   s    



r	   )r   typingr   r   ray.experimental.channelr   ray.experimental.channel.commonr   ray.util.annotationsr   r	   r   r   r   r   <module>   s    