File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,11 +65,15 @@ def getprime(nbits, poolsize):
6565 (pipe_recv , pipe_send ) = mp .Pipe (duplex = False )
6666
6767 # Create processes
68- procs = [mp .Process (target = _find_prime , args = (nbits , pipe_send ))
69- for _ in range (poolsize )]
70- [p .start () for p in procs ]
71-
72- result = pipe_recv .recv ()
68+ try :
69+ procs = [mp .Process (target = _find_prime , args = (nbits , pipe_send ))
70+ for _ in range (poolsize )]
71+ [p .start () for p in procs ]
72+
73+ result = pipe_recv .recv ()
74+ finally :
75+ pipe_recv .close ()
76+ pipe_send .close ()
7377
7478 [p .terminate () for p in procs ]
7579
Original file line number Diff line number Diff line change 1+ """Test for multiprocess prime generation."""
2+
3+ import unittest
4+
5+ import rsa .prime
6+ import rsa .parallel
7+ import rsa .common
8+
9+
10+ class ParallelTest (unittest .TestCase ):
11+ """Tests for multiprocess prime generation."""
12+
13+ def test_parallel_primegen (self ):
14+ p = rsa .parallel .getprime (1024 , 3 )
15+
16+ self .assertFalse (rsa .prime .is_prime (p - 1 ))
17+ self .assertTrue (rsa .prime .is_prime (p ))
18+ self .assertFalse (rsa .prime .is_prime (p + 1 ))
19+
20+ self .assertEqual (1024 , rsa .common .bit_size (p ))
You can’t perform that action at this time.
0 commit comments