|
1 | 1 | """Module containnig a memory memory manager which provides a sliding window on a number of memory mapped files""" |
2 | | -from util import ( |
| 2 | +from .util import ( |
3 | 3 | MapWindow, |
4 | 4 | MapRegion, |
5 | 5 | MapRegionList, |
6 | 6 | is_64_bit, |
7 | | - align_to_mmap |
| 7 | + align_to_mmap, |
| 8 | + string_types, |
8 | 9 | ) |
9 | 10 |
|
10 | 11 | from weakref import ref |
11 | 12 | import sys |
12 | 13 | from sys import getrefcount |
| 14 | +from functools import reduce |
13 | 15 |
|
14 | 16 | __all__ = ["StaticWindowMapManager", "SlidingWindowMapManager", "WindowCursor"] |
15 | 17 | #{ Utilities |
@@ -218,7 +220,7 @@ def fd(self): |
218 | 220 | |
219 | 221 | **Note:** it is not required to be valid anymore |
220 | 222 | :raise ValueError: if the mapping was not created by a file descriptor""" |
221 | | - if isinstance(self._rlist.path_or_fd(), basestring): |
| 223 | + if isinstance(self._rlist.path_or_fd(), string_types()): |
222 | 224 | raise ValueError("File descriptor queried although mapping was generated from path") |
223 | 225 | #END handle type |
224 | 226 | return self._rlist.path_or_fd() |
@@ -256,7 +258,7 @@ class StaticWindowMapManager(object): |
256 | 258 |
|
257 | 259 | _MB_in_bytes = 1024 * 1024 |
258 | 260 |
|
259 | | - def __init__(self, window_size = 0, max_memory_size = 0, max_open_handles = sys.maxint): |
| 261 | + def __init__(self, window_size = 0, max_memory_size = 0, max_open_handles = sys.maxsize): |
260 | 262 | """initialize the manager with the given parameters. |
261 | 263 | :param window_size: if -1, a default window size will be chosen depending on |
262 | 264 | the operating system's architechture. It will internally be quantified to a multiple of the page size |
@@ -306,7 +308,7 @@ def _collect_lru_region(self, size): |
306 | 308 | while (size == 0) or (self._memory_size + size > self._max_memory_size): |
307 | 309 | lru_region = None |
308 | 310 | lru_list = None |
309 | | - for regions in self._fdict.itervalues(): |
| 311 | + for regions in self._fdict.values(): |
310 | 312 | for region in regions: |
311 | 313 | # check client count - consider that we keep one reference ourselves ! |
312 | 314 | if (region.client_count()-2 == 0 and |
@@ -343,7 +345,7 @@ def _obtain_region(self, a, offset, size, flags, is_recursive): |
343 | 345 | r = a[0] |
344 | 346 | else: |
345 | 347 | try: |
346 | | - r = self.MapRegionCls(a.path_or_fd(), 0, sys.maxint, flags) |
| 348 | + r = self.MapRegionCls(a.path_or_fd(), 0, sys.maxsize, flags) |
347 | 349 | except Exception: |
348 | 350 | # apparently we are out of system resources or hit a limit |
349 | 351 | # As many more operations are likely to fail in that condition ( |
@@ -405,7 +407,7 @@ def num_file_handles(self): |
405 | 407 |
|
406 | 408 | def num_open_files(self): |
407 | 409 | """Amount of opened files in the system""" |
408 | | - return reduce(lambda x,y: x+y, (1 for rlist in self._fdict.itervalues() if len(rlist) > 0), 0) |
| 410 | + return reduce(lambda x,y: x+y, (1 for rlist in self._fdict.values() if len(rlist) > 0), 0) |
409 | 411 |
|
410 | 412 | def window_size(self): |
411 | 413 | """:return: size of each window when allocating new regions""" |
@@ -445,7 +447,7 @@ def force_map_handle_removal_win(self, base_path): |
445 | 447 | #END early bailout |
446 | 448 |
|
447 | 449 | num_closed = 0 |
448 | | - for path, rlist in self._fdict.iteritems(): |
| 450 | + for path, rlist in self._fdict.items(): |
449 | 451 | if path.startswith(base_path): |
450 | 452 | for region in rlist: |
451 | 453 | region._mf.close() |
@@ -473,7 +475,7 @@ class SlidingWindowMapManager(StaticWindowMapManager): |
473 | 475 |
|
474 | 476 | __slots__ = tuple() |
475 | 477 |
|
476 | | - def __init__(self, window_size = -1, max_memory_size = 0, max_open_handles = sys.maxint): |
| 478 | + def __init__(self, window_size = -1, max_memory_size = 0, max_open_handles = sys.maxsize): |
477 | 479 | """Adjusts the default window size to -1""" |
478 | 480 | super(SlidingWindowMapManager, self).__init__(window_size, max_memory_size, max_open_handles) |
479 | 481 |
|
|
0 commit comments