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 Oct 26, 2023
1 parent 858e571 commit 303c6c9
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 @@ -1063,9 +1063,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 @@ -1100,9 +1100,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()

Check warning on line 843 in asdf/generic_io.py

View check run for this annotation

Codecov / codecov/patch

asdf/generic_io.py#L842-L843

Added lines #L842 - L843 were not covered by tests
super().truncate(size=size)


class MemoryIO(RandomAccessFile):
"""
Expand Down

0 comments on commit 303c6c9

Please sign in to comment.