Version 2.8: single memory map instead of many

This commit is contained in:
Brandon Rhodes 2018-07-22 16:16:43 -04:00
parent e01a35e1d9
commit 9926bb54cb
3 changed files with 14 additions and 4 deletions

View File

@ -298,6 +298,12 @@ https://github.com/brandon-rhodes/python-jplephem/
Changelog
---------
**2018 July 22 Version 2.8**
* Switched to a making a single memory map of the entire file, to avoid
running out of file descriptors when users load an ephemeris with
hundreds of segments.
**2018 February 11 Version 2.7**
* Expanded the command line tool, most notably with the ability to fetch

View File

@ -27,6 +27,8 @@ class DAF(object):
raise ValueError('file_object must be opened in binary "b" mode')
self.file = file_object
self._map = None
self._array = None
file_record = self.read_record(1)
@ -151,9 +153,11 @@ class DAF(object):
you need random access.
"""
data, skip = self.map_words(start, end)
skip //= 8
return ndarray(end - start + 1 + skip, self.endian + 'd', data)[skip:]
if self._array is None:
self._map, skip = self.map_words(1, self.free - 1)
assert skip == 0
self._array = ndarray(self.free - 1, self.endian + 'd', self._map)
return self._array[start - 1 : end]
def summary_records(self):
"""Yield (record_number, n_summaries, record_data) for each record.

View File

@ -8,7 +8,7 @@ import jplephem
description, long_description = jplephem.__doc__.split('\n', 1)
setup(name = 'jplephem',
version = '2.7',
version = '2.8',
description = description,
long_description = long_description,
license = 'MIT',