File: //opt/cppython/lib/python3.8/site-packages/rsa/__pycache__/parallel.cpython-38.pyc
U
JD�ge � @ s� d Z ddlZddlmZ ddlZddlZeedd�dd�Z eeed�dd �Z
d gZed
kr�e
d� ddlZed�D ]4Ze�� \ZZer� q�ed
dkrrerre
de � qre
d� dS )z�Functions 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)�rsaZrandnumZread_random_odd_int�primeZis_prime�send)r r �integer� r
�9/opt/cppython/lib/python3.8/site-packages/rsa/parallel.py�_find_prime s
r )r �poolsizer c sp t jdd�\}�z6� �fdd�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)Zduplexc s g | ]}t jt� �fd ��qS ))�target�args)�mp�Processr )�.0�_�r Z pipe_sendr
r �
<listcomp>A s zgetprime.<locals>.<listcomp>)r ZPipe�close�range�start�recv� terminate)r r
Z pipe_recvZprocs�p�resultr
r r �getprime* s
r �__main__z'Running doctests 1000x or until failure�d �
z%i timesz
Doctests done)�__doc__�multiprocessingr Zmultiprocessing.connectionr Z rsa.primer Zrsa.randnum�intr r �__all__�__name__�print�doctestr �count�testmodZfailuresZtestsr
r
r
r �<module> s"