a
    ƹDfS                     @   sx   d Z G dd deZG dd deZG dd deZG dd deZG d	d
 d
eZG dd deZG dd deZdS )zB
maps: stand-alone map-like objects using lazy pool instantiation
c                   @   sn   e Zd ZdddZdd Zdd Zdd	 Zd
d ZeeZ	eeZ
eeZdd Zdd Zdd Zdd ZdS )MapNc                 O   sV   | dd| _| d| j| _| d| j| _|tu r:dn|| _|| _|| _d| _dS )a  map instance with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, a builtins.map will be
        used with the returned iterator cast to a list.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        clearFjoincloseN)	pop_clear_join_closemappoolargskwds_poolselfr
   r   r    r   X/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/maps.py__init__   s     zMap.__init__c                 O   s~   | j du rtt|g|R  S | j | ji | j | _}|j|g|R i |}| jr^|   | jrl| 	  | j
rz|   |S )aA  instantiate a pool and execute the pool's map

    Args:
        func: function object to map
        *args: positional arguments for map
        **kwds: keyword arguments for map

    Returns:
        results from execution of ``map(func, *args, **kwds)``

    NOTE: initializes a new worker pool with each call
        N)r
   listr	   r   r   r   r   r   r   r   r   r   )r   funcr   r   r
   resultr   r   r   __call__5   s    
zMap.__call__c                 C   s   | S Nr   r   r   r   r   __cls__L   s    zMap.__cls__c                 C   s   | j jS r   )r   __func__r   r   r   r   __meth__N   s    zMap.__meth__c                 C   s   | j jS r   )r   __get__r   r   r   r   __attr__P   s    zMap.__attr__c                 C   s&   z| j   W n ty    Y n0 dS )zclose the map to any new jobsN)r   r   AttributeErrorr   r   r   r   r   V   s    z	Map.closec                 C   s&   z| j   W n ty    Y n0 dS )zreclaim the closed workersN)r   r   r   r   r   r   r   r   ]   s    zMap.joinc                 C   s&   z| j   W n ty    Y n0 dS )z remove pool singleton, if existsN)r   r   r   r   r   r   r   r   d   s    z	Map.clearc                 C   s:   z|    |   |   W n ty.   Y n0 d| _dS )z-shutdown the worker pool and tidy up
        N)r   r   r   	Exceptionr   r   r   r   r   __del__k   s    zMap.__del__)N)__name__
__module____qualname__r   r   r   r   r   property__self__r   r   r   r   r   r    r   r   r   r   r      s   
(r   c                       s&   e Zd Zd fdd	Zdd Z  ZS )SmapNc                    s   t  j|g|R i | dS )a  starmap instance with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, an itertools.starmap will
        be used with the returned iterator cast to a list.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        Nsuperr   r   	__class__r   r   r   y   s     zSmap.__init__c                    s   | j du r*ddlm} t| g|R  S | j | ji | j | _}t|dt|dd}|du r|j fddg|R i |}n| g|R i |}| j	r| 
  | jr|   | jr|   |S )aQ  instantiate a pool and execute the pool's starmap

    Args:
        func: function object to map
        *args: positional arguments for starmap
        **kwds: keyword arguments for starmap

    Returns:
        results from execution of ``starmap(func, *args, **kwds)``

    NOTE: initializes a new worker pool with each call
        N    starmapsmapr-   c                    s    |  S r   r   xr   r   r   <lambda>       zSmap.__call__.<locals>.<lambda>)r
   	itertoolsr-   r   r   r   r   getattrr	   r   r   r   r   r   r   )r   r   r   r   r-   r
   r.   r   r   r1   r   r      s    
"zSmap.__call__)Nr!   r"   r#   r   r   __classcell__r   r   r)   r   r&   w   s   "r&   c                       s&   e Zd Zd fdd	Zdd Z  ZS )ImapNc                    s   t  j|g|R i | dS )a  map iterator with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, a builtins.map will be
        used.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        Nr'   r   r)   r   r   r      s     zImap.__init__c                 O   s   | j du rt|g|R  S | j | ji | j | _}t|dd}|du rLtS ||g|R i |}| jrp|   | j	r~| 
  | jr|   |S )ae  instantiate a pool and execute the pool's map iterator

    Args:
        func: function object to map
        *args: positional arguments for map iterator
        **kwds: keyword arguments for map iterator

    Returns:
        results from execution of ``map(func, *args, **kwds)`` iterator

    NOTE: initializes a new worker pool with each call
        Nimap)r
   r	   r   r   r   r5   NotImplementedr   r   r   r   r   r   )r   r   r   r   r
   r9   r   r   r   r   r      s    
zImap.__call__)Nr6   r   r   r)   r   r8      s   "r8   c                       s&   e Zd Zd fdd	Zdd Z  ZS )AmapNc                    s   t  j|g|R i | dS )a  async map instance with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, NotImplemented is returned
        upon use.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        Nr'   r   r)   r   r   r      s     zAmap.__init__c                 O   s   | j du rtS | j | ji | j | _}t|dt|dd}|du rHtS ||g|R i |}| jrl|   | jrz| 	  | j
r|   |S )aY  instantiate a pool and execute the pool's async map

    Args:
        func: function object to map
        *args: positional arguments for async map
        **kwds: keyword arguments for async map

    Returns:
        results from execution of async ``map(func, *args, **kwds)``

    NOTE: initializes a new worker pool with each call
        NamapZ	map_asyncr
   r:   r   r   r   r5   r   r   r   r   r   r   )r   r   r   r   r
   r<   r   r   r   r   r     s    
zAmap.__call__)Nr6   r   r   r)   r   r;      s   "r;   c                       s&   e Zd Zd fdd	Zdd Z  ZS )AsmapNc                    s   t  j|g|R i | dS )a  async starmap instance with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, NotImplemented is returned
        upon use.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        Nr'   r   r)   r   r   r   5  s     zAsmap.__init__c                    s   | j du rtS | j | ji | j | _}t|dt|dd}|du rf|j fddg|R i |}n| g|R i |}| jr|   | j	r| 
  | jr|   |S )ai  instantiate a pool and execute the pool's async starmap

    Args:
        func: function object to map
        *args: positional arguments for async starmap
        **kwds: keyword arguments for async starmap

    Returns:
        results from execution of async ``starmap(func, *args, **kwds)``

    NOTE: initializes a new worker pool with each call
        NasmapZstarmap_asyncc                    s    |  S r   r   r/   r1   r   r   r2   i  r3   z Asmap.__call__.<locals>.<lambda>)r
   r:   r   r   r   r5   r<   r   r   r   r   r   r   )r   r   r   r   r
   r?   r   r   r1   r   r   W  s    
"zAsmap.__call__)Nr6   r   r   r)   r   r>   3  s   "r>   c                       s&   e Zd Zd fdd	Zdd Z  ZS )UimapNc                    s   t  j|g|R i | dS )a  unordered map iterator with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, NotImplemented is returned
        upon use.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        Nr'   r   r)   r   r   r   t  s     zUimap.__init__c                 O   s   | j du rtS | j | ji | j | _}t|dt|dd}|du rHtS ||g|R i |}| jrl|   | jrz| 	  | j
r|   |S )a  instantiate a pool and execute the pool's unordered map iterator

    Args:
        func: function object to map
        *args: positional arguments for unordered map iterator
        **kwds: keyword arguments for unordered map iterator

    Returns:
        results from execution of unordered ``map(func, *args, **kwds)`` iterator

    NOTE: initializes a new worker pool with each call
        NuimapZimap_unorderedr=   )r   r   r   r   r
   rA   r   r   r   r   r     s    
zUimap.__call__)Nr6   r   r   r)   r   r@   r  s   "r@   c                       s&   e Zd Zd fdd	Zdd Z  ZS )IsmapNc                    s   t  j|g|R i | dS )a  starmap iterator with internal lazy pool instantiation

    Args:
        pool: pool object (i.e. pathos.pools.ProcessPool)
        *args: positional arguments for pool initialization
        **kwds: keyword arguments for pool initialization
        close: if True, close the pool to any new jobs [Default: False] 
        join: if True, reclaim the pool's closed workers [Default: False]
        clear: if True, delete the pool singleton [Default: False]

    NOTE: if a pool object is not provided, an itertools.starmap will
        be used.
    NOTE: pools from both multiprocess and pathos.pools can be used,
        however the behavior is slightly different. Pools from both
        pathos and multiprocess have close and join methods, to close
        the pool to new jobs, and to shut down the pool's workers.
        Pools from pathos, however, are launched as singletons, so
        they also include a clear method that deletes the singleton.
        In either case, a pool that has been "closed" will throw a
        ValueError if map is then called, and similarly, a ValueError
        will be thrown if join is called before a pool is "closed".
        The major difference is that if a pathos.pool is closed, the
        map instance cannot run new jobs until "clear" is called,
        while a new multiprocess pool will be created each time the
        map is executed. This leads to pathos.pools generally being
        called with either ``clear=True`` or ``clear=False``, and pools
        from multprocess either using ``close=True`` or ``join=True`` or
        both. Some hierarchical parallel workflows are not allowed,
        and will result in an error being thrown; however, changing
        close, join, or clear can often remove the error.
        Nr'   r   r)   r   r   r     s     zIsmap.__init__c                    s   | j du r&ddlm} | g|R  S | j | ji | j | _}t|dd}|du rv|j fddg|R i |}n| g|R i |}| jr| 	  | j
r|   | jr|   |S )au  instantiate a pool and execute the pool's starmap iterator

    Args:
        func: function object to map
        *args: positional arguments for starmap iterator
        **kwds: keyword arguments for starmap iterator

    Returns:
        results from execution of ``starmap(func, *args, **kwds)`` iterator

    NOTE: initializes a new worker pool with each call
        Nr+   r,   ismapc                    s    |  S r   r   r/   r1   r   r   r2     r3   z Ismap.__call__.<locals>.<lambda>)r
   r4   r-   r   r   r   r5   r9   r   r   r   r   r   r   )r   r   r   r   r-   r
   rC   r   r   r1   r   r     s    
"zIsmap.__call__)Nr6   r   r   r)   r   rB     s   "rB   N)	__doc__objectr   r&   r8   r;   r>   r@   rB   r   r   r   r   <module>   s   l@>>?>