a
    ƹDf                     @   sZ   d Z dgZddlmZ ejZejZddlm	Z
 dd Ze
Zi  ZZG dd deZeZdS )	a;  
This module contains map and pipe interfaces to standard (i.e. serial) python.

Pipe methods provided:
    pipe        - blocking communication pipe             [returns: value]

Map methods provided:
    map         - blocking and ordered worker pool      [returns: list]
    imap        - non-blocking and ordered worker pool  [returns: iterator]


Usage
=====

A typical call to a pathos python map will roughly follow this example:

    >>> # instantiate and configure the worker pool
    >>> from pathos.serial import SerialPool
    >>> pool = SerialPool()
    >>>
    >>> # do a blocking map on the chosen function
    >>> print(pool.map(pow, [1,2,3,4], [5,6,7,8]))
    >>>
    >>> # do a non-blocking map, then extract the results from the iterator
    >>> results = pool.imap(pow, [1,2,3,4], [5,6,7,8])
    >>> print("...")
    >>> print(list(results))
    >>>
    >>> # do one item at a time, using a pipe
    >>> print(pool.pipe(pow, 1, 5))
    >>> print(pool.pipe(pow, 2, 6))


Notes
=====

This worker pool leverages the built-in python maps, and thus does not have
limitations due to serialization of the function f or the sequences in args.
The maps in this worker pool have full functionality whether run from a script
or in the python interpreter, and work reliably for both imported and
interactively-defined functions.


SerialPool    )AbstractWorkerPool)mapc                 C   s   | |i |S N )fargskwdsr   r   Z/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/pathos/serial.py<lambda>:       r   c                   @   s   e Zd ZdZdZdd Zejje_dd Zejje_dd Zejje_dd	d
Z	dddZ
dd Zdd Zdd Zdd ZeZeZeeeZeZdS )r   z?
Mapper that leverages standard (i.e. serial) python maps.
    Fc                 O   s   | j r|   t|g|R  S r   )_exiting	_is_alive_mapselfr   r   r	   r   r   r
   r   H   s    zSerialPool.mapc                 O   s   | j r|   t|g|R  S r   )r   r   _imapr   r   r   r
   imapM   s    zSerialPool.imapc                 O   s   | j r|   t|||S r   )r   r   _applyr   r   r   r
   pipeT   s    zSerialPool.pipec                 C   s(   |s| j s| jdd | j r$|   dS )zrestart a closed poolT)negateN)r   r   clear)r   forcer   r   r
   restart[   s    zSerialPool.restartTc                 C   s\   d\}}}dd }|r|n||_ |r8|r8|j |ksXJ n |rP|j ||fv sXJ ntdd S )N)r         c                   S   s   d S r   r   r   r   r   r
   r   d   r   z&SerialPool._is_alive.<locals>.<lambda>zPool not running)_state
ValueError)r   r   runZRUNZCLOSEZ	TERMINATEpoolr   r   r
   r   b   s    
zSerialPool._is_alivec                 C   s
   d| _ dS )zclose the pool to any new jobsTNr   r   r   r   r
   closel   s    zSerialPool.closec                 C   s   |    |   dS )za more abrupt closeN)r"   joinr!   r   r   r
   	terminatep   s    zSerialPool.terminatec                 C   s   | j s| jddd d| _ dS )z#cleanup the closed worker processesTF)r   r   N)r   r   r!   r   r   r
   r#   u   s    zSerialPool.joinc                 C   s
   d| _ dS )zhard restartFNr    r!   r   r   r
   r   {   s    zSerialPool.clearN)F)FT)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r"   r$   r#   r   __get_nodes__Z_SerialPool__get_nodes__set_nodes__Z_SerialPool__set_nodespropertynodes_SerialPool__STATEZ	__state__r   r   r   r
   r   A   s&   






N)r(   __all__Zpathos.abstract_launcherr   Z_AbstractWorkerPool__get_nodesr)   Z_AbstractWorkerPool__set_nodesr*   builtinsr   r   r   r   Z__STATEr-   r   ZPythonSerialr   r   r   r
   <module>   s   +H