Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions plyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ def _read(self, stream, text, byte_order, mmap,
list_prop_names = set(p.name for p in self.properties
if isinstance(p, PlyListProperty))
can_mmap_lists = list_prop_names <= set(known_list_len)
if mmap and _can_mmap(stream) and can_mmap_lists:
mmap_mode = mmap if isinstance(mmap, str) else 'c'
if mmap and _can_mmap(stream, mmap_mode) and can_mmap_lists:
# Loading the data is straightforward. We will memory
# map the file in copy-on-write mode.
mmap_mode = mmap if isinstance(mmap, str) else 'c'
# map the file in the requested mode.
Comment thread
dranjan marked this conversation as resolved.
self._read_mmap(stream, byte_order, mmap_mode,
known_list_len)
else:
Expand Down Expand Up @@ -1434,14 +1434,15 @@ def _write_array(stream, array):
stream.write(array.tobytes())


def _can_mmap(stream):
def _can_mmap(stream, mmap_mode='c'):
"""
Determine if a readable stream can be memory-mapped, using some good
heuristics.

Parameters
----------
stream : open binary file
mmap_mode : {'c', 'r', 'r+'}

Returns
-------
Expand All @@ -1450,7 +1451,7 @@ def _can_mmap(stream):
try:
pos = stream.tell()
try:
_np.memmap(stream, 'u1', 'c')
_np.memmap(stream, 'u1', mmap_mode)
stream.seek(pos)
return True
except Exception:
Expand Down
Loading