Skip to content

Commit

Permalink
All tests work, bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 7, 2015
1 parent 70fae1f commit f071ffd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/source/changes.rst
Expand Up @@ -3,7 +3,7 @@ Changelog
#########

**********
v0.8.6
v0.9.0
**********
- Fixed issue with resources never being freed as mmaps were never closed.
- Client counting is now done manually, instead of relying on pyton's reference count
Expand Down
2 changes: 1 addition & 1 deletion smmap/__init__.py
Expand Up @@ -3,7 +3,7 @@
__author__ = "Sebastian Thiel"
__contact__ = "byronimo@gmail.com"
__homepage__ = "https://github.com/Byron/smmap"
version_info = (0, 8, 5)
version_info = (0, 9, 0)
__version__ = '.'.join(str(i) for i in version_info)

# make everything available in root package for convenience
Expand Down
5 changes: 5 additions & 0 deletions smmap/buf.py
Expand Up @@ -93,6 +93,7 @@ def __getslice__(self, i, j):
l -= len(d)
# This is slower than the join ... but what can we do ...
out += d
del(d)
# END while there are bytes to read
return out
else:
Expand All @@ -103,6 +104,10 @@ def __getslice__(self, i, j):
d = c.buffer()[:l]
ofs += len(d)
l -= len(d)
# Make sure we don't keep references, as c.use_region() might attempt to free resources, but
# can't unless we use pure bytes
if hasattr(d, 'tobytes'):
d = d.tobytes()
md.append(d)
# END while there are bytes to read
return bytes().join(md)
Expand Down
7 changes: 5 additions & 2 deletions smmap/mman.py
Expand Up @@ -58,7 +58,7 @@ def _destroy(self):
# Free all resources associated with the mapped file
self._manager._fdict.pop(self._rlist.path_or_fd())
# END remove regions list from manager
except TypeError:
except (TypeError, KeyError):
# sometimes, during shutdown, getrefcount is None. Its possible
# to re-import it, however, its probably better to just ignore
# this python problem (for now).
Expand All @@ -70,11 +70,14 @@ def _destroy(self):
def _copy_from(self, rhs):
"""Copy all data from rhs into this instance, handles usage count"""
self._manager = rhs._manager
self._rlist = rhs._rlist
self._rlist = type(rhs._rlist)(rhs._rlist)
self._region = rhs._region
self._ofs = rhs._ofs
self._size = rhs._size

for region in self._rlist:
region.increment_client_count()

if self._region is not None:
self._region.increment_client_count()
# END handle regions
Expand Down
3 changes: 2 additions & 1 deletion smmap/test/test_buf.py
Expand Up @@ -12,7 +12,6 @@
from time import time
import sys
import os
import logging


man_optimal = SlidingWindowMapManager()
Expand Down Expand Up @@ -104,6 +103,7 @@ def test_basics(self):
assert len(d) == ofs_end - ofs_start
assert d == data[ofs_start:ofs_end]
num_bytes += len(d)
del d
else:
pos = randint(0, fsize)
assert buf[pos] == data[pos]
Expand All @@ -122,6 +122,7 @@ def test_basics(self):
% (man_id, max_num_accesses, mode_str, type(item), num_bytes / mb, elapsed, (num_bytes / mb) / elapsed),
file=sys.stderr)
# END handle access mode
del buf
# END for each manager
# END for each input
os.close(fd)

0 comments on commit f071ffd

Please sign in to comment.