o
    ̳i{                     @   s   d dl mZ d dlZd dlZd dlmZmZ d dlZd dl	m
Z d dlmZ ddlmZ dedeejejf deejejf d	ed
eejejf f
ddZdS )    N)CallableUnion)ExceptionWrapper   )QUEUE_TIMEOUT	worker_idin_qout_qudf
stop_eventc                 C   s   t d 	 | r| rdS z|jdtd\}}W n
 tjy%   Y qw t|t	r5|j
||fdd n-t|trD|j
||fdd nz||}W n tyX   t	dd}Y nw |j
||fdd q)	aX  _apply_udf assumes in_q emits tuples of (x, idx) where x is the
    payload, idx is the index of the result, potentially used for maintaining
    ordered outputs. For every input it pulls, a tuple (y, idx) is put on the out_q
    where the output of udf(x), an ExceptionWrapper, or StopIteration (if it pulled
    StopIteration from in_q).
    r   T)blocktimeoutF)r   zin _apply_udf)whereN)torchset_num_threadsis_setemptygetr   queueEmpty
isinstancer   putStopIteration	Exception)r   r   r	   r
   r   itemidxy r   N/home/ubuntu/.local/lib/python3.10/site-packages/torchdata/nodes/_apply_udf.py
_apply_udf   s(   


r   )multiprocessing.synchronizesynchronizepython_mp_synchronizer   	threadingtypingr   r   r   torch.multiprocessingmultiprocessingmptorch._utilsr   	constantsr   intQueueEventr   r   r   r   r   <module>   s&   