Repository navigation
Conversation
Properly close memmap file with a public function `close()`
| memmap | ||
|
|
||
| """ | ||
| if self._mmap: |
There was a problem hiding this comment.
Can you explain what the purpose is of this if self._mmap: ... statement?
There was a problem hiding this comment.
self._mmap may be None if it is not mapped or unmapped. Hence I did a check before calling .mmap.close(). Hence calling the function close() from the same fp has no impact, consistent with the standard Python file.close().
There was a problem hiding this comment.
- if self._mmap:
+ if self._mmap is not None:This should be an if not None check in that case,
especially since if mmap(...): ... raises an error if the file is already closed.
There was a problem hiding this comment.
You are correct. Thanks. I have tested the code again, it seems that numpy memmap() does not crash anymore. Need further testing.
The original issue also says
Have you done anything to address this? |
|
Ya, this is not fixed. Need to let Python do a core dump and analyze the issue. It will take times to review. KIV. |
Create a public function
close()to properly close mmapSee Method to explicitly close memmap #13510, there are two ways to un-mapped a memory-mapped file:
a.
del fporb.
fp._mmap.close()The first method may leave the file locked for a long period of time. The second method exposes internal variable
_mmap.The solution provides public function to close the memmap object.