Hello.
I have been working on a project that uses pytables as a storage back-end. I
have recently integrated a third-party module that makes use of the h5py
library, at which point I started having problems with pytables. I narrowed
down the problem to the following test cases:
This code (case A) behaves as expected:
import h5py
import tables
fileh = tables.openFile('test.h5')
Output:
Closing remaining open files: test.h5... done
This code (case B) exhibits the problem behaviour:
import tables
import h5py
fileh = tables.openFile('test.h5')
Output:
Closing remaining open files: test.h5... Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File
"/home/mlui/.virtualenvs/hydrat-dev/lib/python2.6/site-packages/tables/file.py",
line 2323, in close_open_files
fileh.close()
File
"/home/mlui/.virtualenvs/hydrat-dev/lib/python2.6/site-packages/tables/file.py",
line 2127, in close
self.root._f_close()
File
"/home/mlui/.virtualenvs/hydrat-dev/lib/python2.6/site-packages/tables/group.py",
line 982, in _f_close
self._g_close()
File
"/home/mlui/.virtualenvs/hydrat-dev/lib/python2.6/site-packages/tables/group.py",
line 949, in _g_close
self._g_closeGroup()
File "hdf5Extension.pyx", line 699, in
tables.hdf5Extension.Group._g_closeGroup (tables/hdf5Extension.c:6028)
HDF5ExtError: Problems closing the Group /
As you can see the only difference between the two is the order of the
imports.
Additionally, this code (case C) does not exhibit the problem behaviour:
import tables
import h5py
fileh = tables.openFile('test.h5')
fileh.close()
The problem results from when the fileh is being closed by the exitfunc
registered with atexit. These functions are executed LIFO, so in case A,
pytables' exitfunc is executed first, closing the fileh correctly. However,
in case B, h5py's exitfunc is executed first, which somehow causes pytables'
exitfunc to fail.
I have tested this against python-tables 2.1.2-3build1 in Ubuntu 10.04
Lucid, as well as pytables built today from svn REV4585 (version reported
as 2.3b1.dev), against python-h5py 1.2.1-2ubuntu1 in Ubuntu 10.04 Lucid as
well as h5py-1.3.0 installed via pip. The issue is present in all
combinations of the two modules.
As a stopgap measure, I have added
import atexit; atexit.register(lambda: fileh.close())
to my code. As long as this exitfunc will is registered after pytables' and
h5py's, it will always execute first and prevent the problem behaviour from
occurring.
Cheers
Marco
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users