Skip to content

Commit

Permalink
close mmap on windows on update
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 18, 2023
1 parent 6173b89 commit 0c0aef4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions asdf/_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,9 @@ def update(
def rewrite():
self._fd.seek(0)
self._serial_write(self._fd, pad_blocks, include_block_index)
self._fd.truncate()
if self._fd.can_memmap():
self._fd.close_memmap()
self._fd.truncate()

# if we have no read blocks, we can just call write_to as no internal blocks are reused
if len(self._blocks.blocks) == 0:
Expand Down Expand Up @@ -1107,9 +1107,9 @@ def rewrite():

# close memmap to trigger arrays to reload themselves
self._fd.seek(end_of_file)
self._fd.truncate()
if self._fd.can_memmap():
self._fd.close_memmap()
self._fd.truncate()

finally:
self._post_write(fd)
Expand Down
12 changes: 9 additions & 3 deletions asdf/generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,6 @@ def fast_forward(self, size):
self.seek(size, SEEK_CUR)

def truncate(self, size=None):
# windows supports truncating as long as the file not opened
# more than once. So this must be called after closing all
# memmaps
if size is None:
self._fd.truncate()
else:
Expand Down Expand Up @@ -837,6 +834,15 @@ def close(self):
if self._close:
self._fix_permissions()

def truncate(self, size=None):
# windows supports truncating as long as the file not opened
# more than once. So this must be called after closing all
# memmaps
if sys.platform.startswith("win") and hasattr(self, "_mmap"):
self._mmap.close()
self.close_memmap()
super().truncate(size=size)


class MemoryIO(RandomAccessFile):
"""
Expand Down

0 comments on commit 0c0aef4

Please sign in to comment.