U
    ڲge	                     @   s   d Z ddlZddlmZ ddlZddlZeeddddZ	eeeddd	Z
d	gZed
kred ddlZedD ]4Ze \ZZer qed dkrrerrede  qred dS )zFunctions for parallel computation on multiple cores.

Introduced in Python-RSA 3.1.

.. note::

    Requires Python 2.6 or newer.

    N)
Connection)nbitspipereturnc                 C   s,   t j| }t j|r || d S q d S )N)rsaZrandnumZread_random_odd_intprimeZis_primesend)r   r   integer r
   0/tmp/pip-unpacked-wheel-1z1vrokf/rsa/parallel.py_find_prime    s    
r   )r   poolsizer   c                    sp   t jdd\}z6 fddt|D }|D ]}|  q.| }W 5 |    X |D ]}|  q^|S )aU  Returns a prime number that can be stored in 'nbits' bits.

    Works in multiple threads at the same time.

    >>> p = getprime(128, 3)
    >>> rsa.prime.is_prime(p-1)
    False
    >>> rsa.prime.is_prime(p)
    True
    >>> rsa.prime.is_prime(p+1)
    False

    >>> from rsa import common
    >>> common.bit_size(p) == 128
    True

    F)Zduplexc                    s   g | ]}t jt fd qS ))targetargs)mpProcessr   ).0_r   Z	pipe_sendr
   r   
<listcomp>A   s     zgetprime.<locals>.<listcomp>)r   ZPipecloserangestartrecv	terminate)r   r   Z	pipe_recvZprocspresultr
   r   r   getprime*   s    


r   __main__z'Running doctests 1000x or until failured   
   z%i timeszDoctests done)__doc__multiprocessingr   Zmultiprocessing.connectionr   Z	rsa.primer   Zrsa.randnumintr   r   __all____name__printdoctestr   counttestmodZfailurestestsr
   r
   r
   r   <module>   s"   

(