Browse Source

Fix unclosed file handles

pull/203/head
Oliverpool 9 years ago
parent
commit
d3a57ef1a6
  1. 8
      patacrep/songs/__init__.py

8
patacrep/songs/__init__.py

@ -152,16 +152,16 @@ class Song:
def filehash(self):
"""Compute (and cache) the md5 hash of the file"""
if self._filehash is None:
self._filehash = hashlib.md5(
open(self.fullpath, 'rb').read()
).hexdigest()
with open(self.fullpath, 'rb') as songfile:
self._filehash = hashlib.md5(songfile.read()).hexdigest()
return self._filehash
def _cache_retrieved(self):
"""If relevant, retrieve self from the cache."""
if self.use_cache and os.path.exists(self.cached_name):
try:
cached = pickle.load(open(self.cached_name, 'rb',))
with open(self.cached_name, 'rb',) as cachefile:
cached = pickle.load(cachefile)
if (
cached['_filehash'] == self.filehash
and cached['_version'] == self.CACHE_VERSION

Loading…
Cancel
Save