From 2655a68b15f582eca294072e87be51caf9ca0d7c Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Sat, 10 Mar 2012 13:28:32 -0700 Subject: PY3: Fix memmap "ResourceWarning: unclosed file". --- numpy/core/memmap.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'numpy/core') diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 53f9a3f07..fe52b3a09 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -203,8 +203,10 @@ class memmap(ndarray): if hasattr(filename,'read'): fid = filename + own_file = False else: fid = open(filename, (mode == 'c' and 'r' or mode)+'b') + own_file = True if (mode == 'w+') and shape is None: raise ValueError("shape must be given") @@ -263,6 +265,9 @@ class memmap(ndarray): elif hasattr(filename, "name"): self.filename = os.path.abspath(filename.name) + if own_file: + fid.close() + return self def __array_finalize__(self, obj): -- cgit v1.2.1