
    >ie                       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#dS )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.11/site-packages/dask/threaded.py_thread_get_idr      s    !!r   zExecutor | Nonedefault_poolz2defaultdict[threading.Thread, dict[int, Executor]]poolsc                8    | t          j                    d         fS )N   )sysexc_info)edumpss     r   pack_exceptionr   !   s    clnnQr   dskr   keysSequence[Key] | Keyc                   |pt          j        dd          }|pt          j        dd          }t                      }t          5  ||J|t          u rAt
          2t          t                    at          j	        t
          j
                   t
          }n|t          v r#|t          |         v rt          |         |         }ngt          |          }t          j	        |j
                   |t          |         |<   n.t          |t          j        j                  rt!          |          }ddd           n# 1 swxY w Y   t#          |j        |j        | |f|t(          t*          d|}t          5  t-          t/          j                              }|t          ur^t3          t                    D ]I}	|	|vrCt                              |	                                          D ]}
|

                                 Jddd           n# 1 swxY w Y   |S )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)r   r    r%   r$   r#   kwargsthreadresultsactive_threadstps              r   r'   r'   %   sp   B +6:fd++D@M4!@!@KF	 5 5<"v'<'<'#5i#@#@LOL$9:::#5[E&M%A%AV}[1)+66...-1fk**o2788 	5.t44D5 5 5 5 5 5 5 5 5 5 5 5 5 5 5  		
 %	 	 	 	G 
 % %Y02233$$%[[ % %N**"YYq\\0022 % %

% % % % % % % % % % % % % % % Ns&   C"D22D69D6,BH  HH)NNN)r   r   r    r!   )$__doc__
__future__r   r*   multiprocessing.poolr.   r   r3   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>rJ      s    
 # " " " " "      



     # # # # # # - - - - - - - - ; ; ; ; ; ; ; ; * * * * * * * *       = = = = = = = = ! ! ! ! ! !      " " " n $ $ $ $ $<GK<M<M M M M MTVV
      	I I I I I I Ir   