B
    de	                 @   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x>edD ]2Ze \ZZerP ed dkrtertede  qtW e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   s0   x*t j| }t j|r|| d S qW d S )N)rsaZrandnumZread_random_odd_intprimeZis_primesend)r   r   integer r
   >/var/www/html/venv/lib/python3.7/site-packages/rsa/parallel.py_find_prime    s
    
r   )r   poolsizer   c                sx   t jdd\}z: fddt|D }x|D ]}|  q0W | }W d|    X x|D ]}|  qdW |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   	pipe_sendr
   r   
<listcomp>A   s    zgetprime.<locals>.<listcomp>N)r   ZPiperangestartrecvclose	terminate)r   r   Z	pipe_recvZprocspresultr
   )r   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"   
(