def test_range(self): a = parallel.shempty([32], dtype=int) a[:] = -1 r = parallel.range(len(a)) with parallel.fork() as procid: for i in r: a[i] = procid time.sleep(.01) self.assertEqual(min(a), 0) self.assertEqual(max(a), 2 if canfork else 0)
def test_failinchild(self): with self.assertRaisesRegex(Exception, 'fork failed in 2 out of 3 processes'), parallel.fork() as procid: if procid != 0: 1/0
def test_shzeros(self): a = parallel.shzeros([3], dtype=int) with parallel.fork() as procid: a[procid] = 1 self.assertEqual(a.tolist(), [1,1,1] if canfork else [1,0,0])
def test_failinmain(self): with self.assertRaises(ZeroDivisionError), parallel.fork() as procid: if procid == 0: 1/0
def test_fork(self): mask = multiprocessing.RawValue('i', 0) lock = multiprocessing.Lock() with parallel.fork() as procid, lock: mask.value |= 1 << procid self.assertEqual(mask.value, 0b111 if canfork else 1)