async def test_pool_worker_max_tasks(self): tx = get_context().Queue() rx = get_context().Queue() worker = PoolWorker(tx, rx, 1) worker.start() self.assertTrue(worker.is_alive()) tx.put_nowait((1, mapper, (5,), {})) await asyncio.sleep(0.5) result = rx.get_nowait() self.assertEqual(result, (1, 10, None)) self.assertFalse(worker.is_alive()) # maxtasks == 1
async def test_pool_worker_exceptions(self): tx = get_context().Queue() rx = get_context().Queue() worker = PoolWorker(tx, rx) worker.start() self.assertTrue(worker.is_alive()) tx.put_nowait((1, raise_fn, (), {})) await asyncio.sleep(0.5) tid, result, trace = rx.get_nowait() self.assertEqual(tid, 1) self.assertIsNone(result) self.assertIsInstance(trace, str) self.assertIn("RuntimeError: raising", trace) tx.put(None) await worker.join(timeout=0.5) self.assertFalse(worker.is_alive())
async def test_pool_exception_handler(self): exc_q = get_context().Queue() handler = exc_q.put_nowait async with amp.Pool(2, exception_handler=handler) as pool: with self.assertRaises(ProxyException): await pool.apply(raise_fn, args=()) exc = exc_q.get_nowait() self.assertIsInstance(exc, RuntimeError) self.assertEqual(exc.args, ("raising", ))