def test_position_queue_full(self): q = PositionQueue(length=10) for i in xrange(10): q[i] = i self.assertEquals(q.filled, list(xrange(10))) self.assertEquals(len(q), 10) self.assertTrue(q.full())
def join(self, timeout=None, propagate=True): """Gather the results of all tasks in the taskset, and returns a list ordered by the order of the set. :keyword timeout: The number of seconds to wait for results before the operation times out. :keyword propagate: If any of the subtasks raises an exception, the exception will be reraised. :raises celery.exceptions.TimeoutError: if `timeout` is not :const:`None` and the operation takes longer than `timeout` seconds. """ time_start = time.time() results = PositionQueue(length=self.total) while True: for position, pending_result in enumerate(self.subtasks): state = pending_result.state if state in states.READY_STATES: if propagate and state in states.PROPAGATE_STATES: raise pending_result.result results[position] = pending_result.result if results.full(): # Make list copy, so the returned type is not a position # queue. return list(results) else: if (timeout is not None and time.time() >= time_start + timeout): raise TimeoutError("join operation timed out.")
def join(self, timeout=None): """Gather the results for all of the tasks in the taskset, and return a list with them ordered by the order of which they were called. :keyword timeout: The time in seconds, how long it will wait for results, before the operation times out. :raises celery.timer.TimeoutError: if ``timeout`` is not ``None`` and the operation takes longer than ``timeout`` seconds. If any of the tasks raises an exception, the exception will be reraised by :meth:`join`. :returns: list of return values for all tasks in the taskset. """ timeout_timer = TimeoutTimer(timeout) results = PositionQueue(length=self.total) while True: for position, pending_result in enumerate(self.subtasks): if pending_result.status == "DONE": results[position] = pending_result.result elif pending_result.status == "FAILURE": raise pending_result.result if results.full(): # Make list copy, so the returned type is not a position # queue. return list(results) # This raises TimeoutError when timed out. timeout_timer.tick()
def test_position_queue_full(self): q = PositionQueue(length=10) for i in xrange(10): q[i] = i self.assertListEqual(q.filled, list(xrange(10))) self.assertEqual(len(q), 10) self.assertTrue(q.full())
def test_position_queue_unfilled(self): q = PositionQueue(length=10) for position in q.data: self.assertTrue(isinstance(position, q.UnfilledPosition)) self.assertEquals(q.filled, []) self.assertEquals(len(q), 0) self.assertFalse(q.full())
def test_position_queue_unfilled(self): q = PositionQueue(length=10) for position in q.data: self.assertIsInstance(position, q.UnfilledPosition) self.assertListEqual(q.filled, []) self.assertEqual(len(q), 0) self.assertFalse(q.full())
def test_position_queue_almost(self): q = PositionQueue(length=10) q[3] = 3 q[6] = 6 q[9] = 9 self.assertEquals(q.filled, [3, 6, 9]) self.assertEquals(len(q), 3) self.assertFalse(q.full())
def test_position_queue_almost(self): q = PositionQueue(length=10) q[3] = 3 q[6] = 6 q[9] = 9 self.assertListEqual(q.filled, [3, 6, 9]) self.assertEqual(len(q), 3) self.assertFalse(q.full())
def join(self, timeout=None, propagate=True): """Gather the results of all tasks in the taskset, and returns a list ordered by the order of the set. :keyword timeout: The number of seconds to wait for results before the operation times out. :keyword propagate: If any of the subtasks raises an exception, the exception will be reraised. :raises celery.exceptions.TimeoutError: if ``timeout`` is not :const:`None` and the operation takes longer than ``timeout`` seconds. :returns: list of return values for all subtasks in order. """ time_start = time.time() def on_timeout(): raise TimeoutError("The operation timed out.") results = PositionQueue(length=self.total) while True: for position, pending_result in enumerate(self.subtasks): state = pending_result.state if state in states.READY_STATES: if propagate and state in states.PROPAGATE_STATES: raise pending_result.result results[position] = pending_result.result if results.full(): # Make list copy, so the returned type is not a position # queue. return list(results) else: if (timeout is not None and time.time() >= time_start + timeout): on_timeout()
def join(self, timeout=None): """Gather the results for all of the tasks in the taskset, and return a list with them ordered by the order of which they were called. :keyword timeout: The time in seconds, how long it will wait for results, before the operation times out. :raises celery.exceptions.TimeoutError: if ``timeout`` is not ``None`` and the operation takes longer than ``timeout`` seconds. If any of the tasks raises an exception, the exception will be reraised by :meth:`join`. :returns: list of return values for all tasks in the taskset. """ time_start = time.time() def on_timeout(): raise TimeoutError("The operation timed out.") results = PositionQueue(length=self.total) while True: for position, pending_result in enumerate(self.subtasks): if pending_result.status == states.SUCCESS: results[position] = pending_result.result elif pending_result.status == states.FAILURE: raise pending_result.result if results.full(): # Make list copy, so the returned type is not a position # queue. return list(results) else: if timeout is not None and \ time.time() >= time_start + timeout: on_timeout()
def join(self, timeout=None): """Gather the results for all of the tasks in the taskset, and return a list with them ordered by the order of which they were called. :keyword timeout: The time in seconds, how long it will wait for results, before the operation times out. :raises celery.exceptions.TimeoutError: if ``timeout`` is not ``None`` and the operation takes longer than ``timeout`` seconds. If any of the tasks raises an exception, the exception will be reraised by :meth:`join`. :returns: list of return values for all tasks in the taskset. """ time_start = time.time() def on_timeout(): raise TimeoutError("The operation timed out.") results = PositionQueue(length=self.total) while True: for position, pending_result in enumerate(self.subtasks): if pending_result.status == states.SUCCESS: results[position] = pending_result.result elif pending_result.status in states.PROPAGATE_STATES: raise pending_result.result if results.full(): # Make list copy, so the returned type is not a position # queue. return list(results) else: if timeout is not None and \ time.time() >= time_start + timeout: on_timeout()