
    Mh                    x    d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	  G d d          Z
 e
            Zdd	gZdS )
z(Tracker for zero-copy messages with 0MQ.    )annotationsN)Event)Frame)NotDonec                  P    e Zd ZU dZded<   ded<   ddZed	             ZdddZdS )MessageTrackera  A class for tracking if 0MQ is done using one or more messages.

    When you send a 0MQ message, it is not sent immediately. The 0MQ IO thread
    sends the message at some later time. Often you want to know when 0MQ has
    actually sent the message though. This is complicated by the fact that
    a single 0MQ message can be sent multiple times using different sockets.
    This class allows you to track all of the 0MQ usages of a message.

    Parameters
    ----------
    towatch : Event, MessageTracker, zmq.Frame
        This objects to track. This class can track the low-level
        Events used by the Message class, other MessageTrackers or
        actual Messages.
    z
set[Event]eventszset[MessageTracker]peerstowatch%tuple[MessageTracker | Event | Frame]c                   t                      | _        t                      | _        |D ]}t          |t                    r| j                            |           2t          |t                    r| j                            |           bt          |t                    r6|j        st          d          | j                            |j                   t          dt          |                     dS )a\  Create a message tracker to track a set of messages.

        Parameters
        ----------
        *towatch : tuple of Event, MessageTracker, Message instances.
            This list of objects to track. This class can track the low-level
            Events used by the Message class, other MessageTrackers or
            actual Messages.
        zNot a tracked messagez&Require Events or Message Frames, not N)setr	   r
   
isinstancer   addr   r   tracker
ValueError	TypeErrortype)selfr   objs      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/zmq/sugar/tracker.py__init__zMessageTracker.__init__#   s     eeUU
 
	V 
	VC#u%% 	V$$$$C00 V
s####C'' V{ >$%<===
s{++++ Tc T TUUU
	V 
	V    c                p    | j         D ]}|                                s dS | j        D ]}|j        s dS dS )z9Is 0MQ completely done with the message(s) being tracked?FT)r	   is_setr
   done)r   evtpms      r   r   zMessageTracker.done;   s]     ; 	 	C::<< uu* 	 	B7 uutr   timeoutfloat | intc                   t          j                     }|du s|dk     rd}n|}| j        D ]]}|dk     rt          |                    |           |                                st          t          j                     }|||z
  z  }|}^| j        D ]B}|dk     rt          |                    |           t          j                     }|||z
  z  }|}CdS )a  Wait for 0MQ to be done with the message or until `timeout`.

        Parameters
        ----------
        timeout : float
            default: -1, which means wait forever.
            Maximum time in (s) to wait before raising NotDone.

        Returns
        -------
        None
            if done before `timeout`

        Raises
        ------
        NotDone
            if `timeout` reached before I am done.
        Fr   i:	 )r    N)timer	   r   waitr   r
   )r   r    tic	remainingr   tocpeers          r   r$   zMessageTracker.waitF   s    & ikkew{{%III; 	 	C1}}HHYH'''::<< )++Cs"ICCJ 	 	D1}}IIiI((()++Cs"ICC	 	r   N)r   r   )r   )r    r!   )	__name__
__module____qualname____doc____annotations__r   propertyr   r$    r   r   r   r      s            V V V V0   X) ) ) ) ) ) )r   r   _FINISHED_TRACKER)r,   
__future__r   r#   	threadingr   zmq.backendr   	zmq.errorr   r   r0   __all__r/   r   r   <module>r6      s    . .
 # " " " " "                   ` ` ` ` ` ` ` `F #N$$ 0
1r   