[Python-modules-team] Bug#679998: regression -- closes not-owned file handle upon numpy.load of .npz

Yaroslav Halchenko debian at onerussian.com
Mon Jul 2 21:26:08 UTC 2012


Package: python-numpy
Version: 1:1.6.2-1
Severity: important
Tags: upstream patch

This bug causes FTBFS of pyNN due to being triggered by the tests (built fine
before).

I have reported it upstream
http://projects.scipy.org/numpy/ticket/2178
and  sent a tentative unittest + patch (diffs attached) 
https://github.com/numpy/numpy/pull/328

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (900, 'testing'), (600, 'unstable'), (300, 'experimental'), (100, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.1.0-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages python-numpy depends on:
ii  libblas3gf [libblas.so.3gf]      1.2.20110419-2
ii  libc6                            2.13-33
ii  libgcc1                          1:4.7.1-2
ii  libgfortran3                     4.7.1-2
ii  liblapack3gf [liblapack.so.3gf]  3.3.1-1
ii  libquadmath0                     4.7.1-2
ii  python                           2.7.2-10
ii  python-support                   1.0.14

python-numpy recommends no packages.

Versions of packages python-numpy suggests:
ii  gcc               4:4.7.1-1
ii  gfortran          4:4.6.1-2
ii  python-dev        2.7.2-10
ii  python-nose       1.1.2-3
ii  python-numpy-dbg  1:1.6.2-1
ii  python-numpy-doc  1:1.5.1-4

-- no debconf information
-------------- next part --------------
>From 4df244465c3db3a8e9e624d17ed2982f595e2b8a Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <debian at onerussian.com>
Date: Mon, 2 Jul 2012 16:03:53 -0400
Subject: [PATCH 1/2] BUG: do not "own" the FID for GzipFile and file if
 provided to load already opened (ticket #2178)

Also made all assignments of own_file go in pair with assignments to fid to make things clearer
---
 numpy/lib/npyio.py |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 2215299..e16485f 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -2,6 +2,9 @@ __all__ = ['savetxt', 'loadtxt', 'genfromtxt', 'ndfromtxt', 'mafromtxt',
            'recfromtxt', 'recfromcsv', 'load', 'loads', 'save', 'savez',
            'savez_compressed', 'packbits', 'unpackbits', 'fromregex', 'DataSource']
 
+# Price to pay for overloading standard keywords
+import __builtin__
+
 import numpy as np
 import format
 import sys
@@ -353,14 +356,19 @@ def load(file, mmap_mode=None):
     """
     import gzip
 
-    own_fid = False
     if isinstance(file, basestring):
-        fid = open(file, "rb")
         own_fid = True
+        fid = open(file, "rb")
     elif isinstance(file, gzip.GzipFile):
+        # we were provided an existing handle which we should close
+        # only if it was closed already
+        own_fid = file.closed
         fid = seek_gzip_factory(file)
-        own_fid = True
+    elif isinstance(file, __builtin__.file):
+        own_fid = file.closed
+        fid = file
     else:
+        own_fid = False
         fid = file
 
     try:
@@ -371,7 +379,7 @@ def load(file, mmap_mode=None):
         fid.seek(-N, 1) # back-up
         if magic.startswith(_ZIP_PREFIX):  # zip-file (assume .npz)
             own_fid = False
-            return NpzFile(fid, own_fid=True)
+            return NpzFile(fid, own_fid=own_fid)
         elif magic == format.MAGIC_PREFIX: # .npy file
             if mmap_mode:
                 return format.open_memmap(file, mode=mmap_mode)
-- 
1.7.10

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-ENH-unittest-for-preceeding-commit-fixing-2178.patch
Type: text/x-c++
Size: 1385 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/python-modules-team/attachments/20120702/61b1c364/attachment-0001.bin>


More information about the Python-modules-team mailing list