-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure memory-mapped files are safely closed #81
Conversation
* Add `io.MMapArray`, an array_like type that uses a memory-mapped file buffer for storage * Replace usage of `numpy.memmap` with `io.MMapArray` `numpy.memmap` does not have an API that guarantees that the underlying file is closed. This could lead to a large number of file descriptors staying open for much longer than necessary. >Currently there is no API to close the underlying mmap. It is tricky to >ensure the resource is actually closed, since it may be shared between >different memmap instances. https://numpy.org/doc/stable/reference/generated/numpy.memmap.html In practice, this seems to have been the cause of errors encountered in testing due to too many open files when unwrapping multiple interferograms in parallel. ``` OSError: [Errno 24] Too many open files ```
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
==========================================
- Coverage 93.44% 91.97% -1.48%
==========================================
Files 9 10 +1
Lines 473 548 +75
==========================================
+ Hits 442 504 +62
- Misses 31 44 +13 ☔ View full report in Codecov by Sentry. |
not related to this PR, but i retried an editable install after checking out the branch, and it didn't error on install... but then I got this during the run File "/Users/staniewi/repos/snaphu-py/src/snaphu/_conncomp.py", line 307, in grow_conncomps
regrow_conncomp_from_unw(
File "/Users/staniewi/repos/snaphu-py/src/snaphu/_conncomp.py", line 110, in regrow_conncomp_from_unw
run_snaphu(config_file)
File "/Users/staniewi/repos/snaphu-py/src/snaphu/_snaphu.py", line 89, in run_snaphu
subprocess.run(args, stderr=subprocess.PIPE, check=True, text=True)
File "/Users/staniewi/miniconda3/envs/mapping-311/lib/python3.11/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/staniewi/miniconda3/envs/mapping-311/lib/python3.11/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Users/staniewi/miniconda3/envs/mapping-311/lib/python3.11/subprocess.py", line 1950, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/staniewi/repos/snaphu-py/src/snaphu/snaphu' so I wonder if it's possible to support that for testing |
Unfortunately i dont think this is working (on Mac still). I dont quite get why Also just clarifying- this is not doing any parallel processing; it's just unwrapping each interferogram in serial |
@scottstanie found this issue which will be fixed in the next Python release (v3.13) with the addition of the |
Closing this in favor of #82 |
Adds a new class
io.MMapArray
, an array_like type that uses a memory-mapped file buffer for storage, and replaces usage ofnumpy.memmap
withio.MMapArray
throughout the codebase.numpy.memmap
does not have an API that guarantees that the underlying file is closed:This could lead to a large number of file descriptors staying open for much longer than necessary. It seems to have been the cause of errors encountered in @scottstanie's testing due to too many open files when unwrapping multiple interferograms in parallel.
TODO: fix pre-commit failures, finish docstrings, add unit tests
@scottstanie will you please test this out and see if it resolves the issue for you?