Skip to content

Commit

Permalink
Merge pull request dbr#21 from webitup/master
Browse files Browse the repository at this point in the history
Garbage collect ShowContainer
  • Loading branch information
dbr committed May 11, 2012
2 parents fc497dc + b036905 commit 9f99ca4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tvdb_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
__author__ = "dbr/Ben"
__version__ = "1.6.4"

import os
import os, time
import urllib
import urllib2
import StringIO
Expand Down Expand Up @@ -53,7 +53,26 @@ def log():
class ShowContainer(dict):
"""Simple dict that holds a series of Show instances
"""
pass

_stack = []
_lastgc = time.time()

def __setitem__(self, key, value):
self._stack.append(key)

#keep only the 100th latest results
if time.time() - self._lastgc > 20:
tbd = self._stack[:-100]
i = 0
for o in tbd:
del self[o]
del self._stack[i]
i += 1

_lastgc = time.time()
del tbd

super(ShowContainer, self).__setitem__(key, value)


class Show(dict):
Expand Down

0 comments on commit 9f99ca4

Please sign in to comment.