
    Lg                       U d Z ddlmZ ddlZddlZddlZddlZddlm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ d Z e       Zdaded<    e	e      Z ded<    e       Z!d Z"	 	 	 d	 	 	 ddZ#y)z2
A threaded shared-memory scheduler

See local.py
    )annotationsN)defaultdict)MappingSequence)ExecutorThreadPoolExecutor)Lockcurrent_thread)config)MultiprocessingPoolExecutor	get_async)	CPU_COUNT)Keyc                 *    t               j                  S )N)r
   ident     -lib/python3.12/site-packages/dask/threaded.py_thread_get_idr      s    !!!r   zExecutor | Nonedefault_poolz2defaultdict[threading.Thread, dict[int, Executor]]poolsc                4    | t        j                         d   fS )N   )sysexc_info)edumpss     r   pack_exceptionr   "   s    cllnQr   c                   |xs t        j                  dd      }|xs t        j                  dd      }t               }t        5  ||G|t        u r?t
        2t        t              at        j                  t
        j                         t
        }n|t        v r|t        |   v rt        |   |   }nft        |      }t        j                  |j                         |t        |   |<   n/t        |t        j                  j                        rt!        |      }ddd       t#        |j$                  |j&                  | |f|t(        t*        d|}t        5  t-        t/        j0                               }|t        urQt3        t              D ]?  }	|	|vst        j5                  |	      j7                         D ]  }
|
j                           A ddd       |S # 1 sw Y   xY w# 1 sw Y   |S xY w)a  Threaded cached implementation of dask.get

    Parameters
    ----------

    dsk: dict
        A dask dictionary specifying a workflow
    keys: key or list of keys
        Keys corresponding to desired data
    num_workers: integer of thread count
        The number of threads to use in the ThreadPool that will actually execute tasks
    cache: dict-like (optional)
        Temporary storage of results

    Examples
    --------
    >>> inc = lambda x: x + 1
    >>> add = lambda x, y: x + y
    >>> dsk = {'x': 1, 'y': 2, 'z': (inc, 'x'), 'w': (add, 'z', 'y')}
    >>> get(dsk, 'w')
    4
    >>> get(dsk, ['w', 'y'])
    (4, 2)
    poolNnum_workers)cacheget_idr   )r   getr
   
pools_lockmain_threadr   r   r   atexitregistershutdownr   
isinstancemultiprocessingr    Poolr   r   submit_max_workersr   r   set	threading	enumeratelistpopvalues)dskkeysr"   r!   r    kwargsthreadresultsactive_threadstps              r   r$   r$   &   s   B +6::fd+D@M4!@KF	<"v'<'#5i#@LOOL$9$9:#5[E&M%AV}[1)+6.-1fk*o22778.t4D 
  		
 %	 	G 
Y0023$%[N*"YYq\002

 3 ! 
 NI 
8 
 Ns   CG<G!:G!G!G+)NNN)r5   r   r6   zSequence[Key] | Key)$__doc__
__future__r   r'   multiprocessing.poolr+   r   r0   collectionsr   collections.abcr   r   concurrent.futuresr   r   r	   r
   daskr   
dask.localr   r   dask.systemr   dask.typingr   r   r&   r   __annotations__dictr   r%   r   r$   r   r   r   <module>rI      s    #   
  # - ; *  = ! "  $o $<G<M9 MV
  	I	I
Ir   