Skip to content

Commit

Permalink
define a task cache to not keep references of tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
parkouss committed Jun 17, 2015
1 parent 95388c7 commit 418c973
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rcontrol/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ def new_meth(self, *args, **kwargs):
return new_meth


class TaskCache(object):
def __init__(self):
self._cache = set()

def update(self, tasks):
self._cache.update(id(t) for t in tasks)

def __contains__(self, task):
return id(task) in self._cache


@six.add_metaclass(abc.ABCMeta)
class BaseSession(object):
"""
Expand Down Expand Up @@ -180,7 +191,7 @@ def wait_for_tasks(self, raise_if_error=True):
errors = []
# in case tasks do not unregister themselves we do not want to
# loop infinitely
tasks_seen = set()
tasks_seen = TaskCache()
# we do a while loop to ensure that tasks started from callbacks
# are waited too.
while True:
Expand Down

0 comments on commit 418c973

Please sign in to comment.