##// END OF EJS Templates
allow purging local results as long as they are not outstanding...
MinRK -
Show More
@@ -1661,15 +1661,13 class Client(HasTraits):
1661 return msg_ids
1661 return msg_ids
1662
1662
1663 def purge_local_results(self, jobs=[], targets=[]):
1663 def purge_local_results(self, jobs=[], targets=[]):
1664 """Clears the client caches of results and frees such memory.
1664 """Clears the client caches of results and their metadata.
1665
1665
1666 Individual results can be purged by msg_id, or the entire
1666 Individual results can be purged by msg_id, or the entire
1667 history of specific targets can be purged.
1667 history of specific targets can be purged.
1668
1668
1669 Use `purge_local_results('all')` to scrub everything from the Clients's db.
1669 Use `purge_local_results('all')` to scrub everything from the Clients's
1670
1670 results and metadata caches.
1671 The client must have no outstanding tasks before purging the caches.
1672 Raises `AssertionError` if there are still outstanding tasks.
1673
1671
1674 After this call all `AsyncResults` are invalid and should be discarded.
1672 After this call all `AsyncResults` are invalid and should be discarded.
1675
1673
@@ -1683,24 +1681,30 class Client(HasTraits):
1683
1681
1684 jobs : str or list of str or AsyncResult objects
1682 jobs : str or list of str or AsyncResult objects
1685 the msg_ids whose results should be purged.
1683 the msg_ids whose results should be purged.
1686 targets : int/str/list of ints/strs
1684 targets : int/list of ints
1687 The targets, by int_id, whose entire results are to be purged.
1685 The engines, by integer ID, whose entire result histories are to be purged.
1686
1687 Raises
1688 ------
1689
1690 RuntimeError : if any of the tasks to be purged are still outstanding.
1688
1691
1689 default : None
1690 """
1692 """
1691 assert not self.outstanding, "Can't purge a client with outstanding tasks!"
1692
1693 if not targets and not jobs:
1693 if not targets and not jobs:
1694 raise ValueError("Must specify at least one of `targets` and `jobs`")
1694 raise ValueError("Must specify at least one of `targets` and `jobs`")
1695
1695
1696 if jobs == 'all':
1696 if jobs == 'all':
1697 if self.outstanding:
1698 raise RuntimeError("Can't purge outstanding tasks: %s" % self.outstanding)
1697 self.results.clear()
1699 self.results.clear()
1698 self.metadata.clear()
1700 self.metadata.clear()
1699 return
1700 else:
1701 else:
1701 msg_ids = []
1702 msg_ids = set()
1702 msg_ids.extend(self._build_msgids_from_target(targets))
1703 msg_ids.update(self._build_msgids_from_target(targets))
1703 msg_ids.extend(self._build_msgids_from_jobs(jobs))
1704 msg_ids.update(self._build_msgids_from_jobs(jobs))
1705 still_outstanding = self.outstanding.intersection(msg_ids)
1706 if still_outstanding:
1707 raise RuntimeError("Can't purge outstanding tasks: %s" % still_outstanding)
1704 for mid in msg_ids:
1708 for mid in msg_ids:
1705 self.results.pop(mid)
1709 self.results.pop(mid)
1706 self.metadata.pop(mid)
1710 self.metadata.pop(mid)
General Comments 0
You need to be logged in to leave comments. Login now