Skip to content

Commit

Permalink
Fixed a few things:
Browse files Browse the repository at this point in the history
Added a... not very ugly hack to clean zombie processes left behind by
audiotools.
Added an import statement at top of bootstrap
Added a hooking method to the Collector in garbage
  • Loading branch information
Wessie committed Oct 31, 2012
1 parent 3572f0c commit 1c462bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions audio/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def collect(self):
self.item._reader.close()
except (audiotools.DecodingError):
pass
# Hack to kill zombies below
import gc, subprocess
try:
[item.poll() for item in gc.get_referrers(subprocess.Popen)
if isinstance(item, subprocess.Popen)]
except:
logger.warning("Exception occured in hack.")
# Hack to kill zombies above

return True


Expand Down
1 change: 1 addition & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config
import logging
import time

logging.getLogger().setLevel(config.loglevel)

Expand Down
12 changes: 11 additions & 1 deletion garbage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ def __call__(mcs, *args, **kw):

class Collector(object):
__metaclass__ = Singleton
_hooks = list()
def __init__(self):
super(Collector, self).__init__()
self.items = set()


self.collecting = threading.Event()
self.thread = threading.Thread(target=self.run,
name="Garbage Collection Thread")
Expand All @@ -31,7 +33,12 @@ def __init__(self):

def add(self, garbage):
self.items.add(garbage)

for hook in self._hooks:
try:
hook(garbage)
except:
logger.exception("Hook function exception.")

def run(self):
while not self.collecting.is_set():
removal = set()
Expand All @@ -51,6 +58,9 @@ def info(self):
about current pending garbage."""
yield None # Not implemented

@classmethod
def add_hook(cls, hook):
cls._hooks.append(hook)

class Garbage(object):
collector = Collector()
Expand Down

0 comments on commit 1c462bd

Please sign in to comment.