
    Cd!                    *   U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlZd dlmZ d dlmZmZmZ d d	lmZmZ d d
lmZ d dlm Z  d Z! ej         e"e#j$                  e!            eej%        ej&                  Z'ej(        Z)d Z* G d de+          Z,i Z-de.d<   d%dZ/	 d dl0Z1e1j2        3                                 d Z4n# e5$ r
 d Z4d&dZY nw xY wd Z6dZ7d Z8	 	 	 	 	 	 	 d'd(d"Z9d# Z:d&d$Z;dS ))    )annotationsN)HashableMappingSequence)ProcessPoolExecutor)partial)warn)config)MultiprocessingPoolExecutor	get_asyncreraise)cullfuse)	CPU_COUNT)ensure_dictc                ,    t           | j        | j        ffS N)getattr__objclass____name__)ms    4lib/python3.11/site-packages/dask/multiprocessing.py_reduce_method_descriptorr      s    Q^QZ000    )protocolc                 2    t          j                    j        S r   )multiprocessingcurrent_processident r   r   _process_get_idr!   #   s    *,,22r   c                  *    e Zd ZdZd Zd Zd Zd ZdS )RemoteExceptionzXRemote Exception

    Contains the exception and traceback from a remotely run task
    c                "    || _         || _        d S r   )	exception	traceback)selfr%   r&   s      r   __init__zRemoteException.__init__:   s    ""r   c                @    t          | j                  dz   | j        z   S )Nz

Traceback
---------
)strr%   r&   r'   s    r   __str__zRemoteException.__str__>   s    4>""%AADNRRr   c           	         t          t          t          t          |                     t	          | j                  z   t          | j                  z                       S r   )sortedsetdirtypelist__dict__r%   r+   s    r   __dir__zRemoteException.__dir__A   sB    c#d4jj//D,?,??#dnBUBUUVVWWWr   c                    	 t                               | |          S # t          $ r t          | j        |          cY S w xY wr   )object__getattribute__AttributeErrorr   r%   )r'   keys     r   __getattr__zRemoteException.__getattr__D   sP    	0**4555 	0 	0 	04>3/////	0s    ??N)r   
__module____qualname____doc__r(   r,   r4   r:   r    r   r   r#   r#   4   s`         
# # #S S SX X X0 0 0 0 0r   r#   z&dict[type[Exception], type[Exception]]
exceptionsexc	Exceptionreturnc                b   t          |           t          v r&t          t          |                    } || |          S 	 t          | j        j        t          t          |           fdt          |           i          }|t          t          |           <    || |          S # t
          $ r | cY S w xY w)z6Metaclass that wraps exception type in RemoteExceptionexception_type)r1   r>   	__class__r   r#   	TypeError)r?   tbtyps      r   remote_exceptionrH   N   s    CyyJc#s3||		& $s)),!499- C
 %(JtCyy!3sB<< 	 	 	JJJ	s   A B B.-B.c                    | S r   r    rF   s    r   _pack_tracebackrK   e   s    	r   c                P    d                     t          j        |                     S )N )joinr&   	format_tbrJ   s    r   rK   rK   j   s    wwy*2..///r   c                &    t          | |          } | r   )rH   )r?   rF   s     r   r   r   m   s    sB''	r   c                   t          j                    \  }}}t          |          }	  || |f          }nJ# t          $ r=} t          j                    \  }}}t          |          } || |f          }Y d } ~ nd } ~ ww xY w|S r   )sysexc_inforK   BaseException)edumpsexc_type	exc_valueexc_tracebackrF   results          r   pack_exceptionr[   r   s    ),&Hi		'	'B 2w      -0\^^*)]]++2w  Ms   6 
A= 3A88A=zThe 'multiprocessing.context' configuration option will be ignored on Python 2
and on Windows, because they each only support a single context.
c                     t          j        dd          } t          j        dk    r'| dk    rt	          t
          t                     t          S t          j        |           S )z+Return the current multiprocessing context.zmultiprocessing.contextspawnwin32)	r
   getrR   platformr	   _CONTEXT_UNSUPPORTEDUserWarningr   get_context)context_names    r   rc   rc      sV     :7AAL
|w7""%{333*<888r   Tdskr   keysSequence[Hashable] | Hashablec	           
        |pt          j        dd          }|pt          j        dd          }|pt          j        dd          }|pt          j        dd          pt          }|it          j                            d          dv rd	t          j        d<   t                      }
t          t          |
          }t          ||
|          }d}nA|t          d           t          |t          j        j                  rt          |          }d}t          |           } t!          | |          \  }}|rt#          |||          \  }}n|}|pt          j        dd          pt$          }|pt          j        dd          pt&          }	 t)          |j        |j        ||ft.          ||t0          t2          |d|	}|r|                                 n# |r|                                 w w xY w|S )a   Multiprocessed get function appropriate for Bags

    Parameters
    ----------
    dsk : dict
        dask graph
    keys : object or list
        Desired results from graph
    num_workers : int
        Number of worker processes (defaults to number of cores)
    func_dumps : function
        Function to use for function serialization (defaults to cloudpickle.dumps)
    func_loads : function
        Function to use for function deserialization (defaults to cloudpickle.loads)
    optimize_graph : bool
        If True [default], `fuse` is applied to the graph before computation.
    pool : Executor or Pool
        Some sort of `Executor` or `Pool` to use
    initializer: function
        Ignored if ``pool`` has been set.
        Function to initialize a worker process before running any tasks in it.
    chunksize: int, optional
        Size of chunks to use when dispatching work.
        Defaults to 5 as some batching is helpful.
        If -1, will be computed to evenly divide ready work across workers.
    	chunksize   poolNzmultiprocessing.initializernum_workersPYTHONHASHSEED)N06640user_initializer)
mp_contextinitializerTzThe ``initializer`` argument is ignored when ``pool`` is provided. The user should configure ``pool`` with the needed ``initializer`` on creation.F
func_loads
func_dumps)get_idrV   loadsr[   raise_exceptionri   )r
   r_   r   osenvironrc   r   initialize_worker_processr   r	   
isinstancer   rk   Poolr   r   r   r   _loads_dumpsr   submit_max_workersr!   r[   r   shutdown)re   rf   rl   rt   ru   optimize_graphrk   rs   ri   kwargscontextcleanupdsk2dependenciesdsk3rw   rV   rZ   s                     r   r_   r_      s&   L 7VZQ77I+6:fd++DP,I4!P!PKMM4!@!@MIK| :>>*++{:: ,2BJ'(--7+VVV"G
 
 
 "  
 dO0566 	5.t44D c

Cc4D, !$l;;ll B&*\488BFEB&*\488BFE
K	

 #)#
 
 
 
  	MMOOO  	MMOOOO	Ms   0G G(c                 ~    t           j                            d          } | | j                                         d S d S )Nnumpy)rR   modulesr_   randomseed)nps    r   default_initializerr      s;     
	!	!B	~
	 ~r   c                >    t                       |  |              dS dS )zE
    Initialize a worker process before running any tasks in it.
    N)r   rp   s    r   r{   r{     s3     # $#r   )r?   r@   rA   r@   r   )NNNTNNN)re   r   rf   rg   )<
__future__r   copyregr   multiprocessing.poolry   picklerR   r&   collections.abcr   r   r   concurrent.futuresr   	functoolsr   warningsr	   cloudpickledaskr
   
dask.localr   r   r   dask.optimizationr   r   dask.systemr   
dask.utilsr   r   r1   r/   unionrV   HIGHEST_PROTOCOLr   rw   r~   r!   r@   r#   r>   __annotations__rH   tblib.pickling_supporttblibpickling_supportinstallrK   ImportErrorr[   ra   rc   r_   r   r{   r    r   r   <module>r      s   " " " " " " "          				  



     7 7 7 7 7 7 7 7 7 7 2 2 2 2 2 2                       F F F F F F F F F F ( ( ( ( ( ( ( ( ! ! ! ! ! ! " " " " " "1 1 1
 ttCI 9 : : :	"V-D	E	E	E		3 3 3"0 0 0 0 0i 0 0 0. 68
 7 7 7 7   $!!!!	""$$$       0 0 0     	 	 	 9 9 9" 	g g g g gT       s    C& &C54C5