Tuesday 15 July 2014

Python dictionary too full or something else? -


I have approximately 1300 H5 files that are used to sort in a dictionary using h5py. Code runs around 250 files, it works fine, but any major error is given to me:

  traceback (most recent call final): file "solution_script.py ", Line 31, & lt; Module & gt; File "Construction / bdist.macosx-10.7- Intel / egg / h5py / _hl / files.py", line 165, __init__ file "Construction / bdist.macosx-10.7- Intel / egg / h5py / _hl / files.py in" , line 57, make_fid file "h5f.pyx", line 70, IOError in h5py.h5f.open (h5py / h5f.c: 1626): (file accessibility: unable to open unable) file to open the file '   

I'm not sure if I'm installing a wrong dictionary or if there's a better way to do this.

This is my code if someone can see some obvious mistakes I 've created:

  nodesDictionary = {} velDictionary = {} cellsDictionary = {} num_h5file = -1 ; Sort (for file in files) to the root, files directory, Oskwalk (RootDirectory) if file.endswith ( "h5."): Num_h5file = num_h5file + 1 curh5file = h5py.File (file, 'R' ) nodes_list = curh5file [ "nodes"] cells_list = curh5file [ "cell"] velocity_list = curh5file in [ "velocity"] range of I (0, len (nodes_list) -1): If num_h5file not nodesDictionary: nodesDictionary [num_h5file ] = [curh5file [ "nodes"] [i]] velDictionary [num_h5file] = [curh5file [ "velocity"] [i]] all other: nodesDictionary [num_h5file] .append (curh5file [ "nodes"] [i]) velDictionary [Num_h5file] .append (curh5file ["velocity"] [i]) for range j (0, lane (cells_list) -1): if num _h5file not cellsDictionary: cellsDictionary [num_h5file] = [curh5file [ "cell"] [j]] Else: cellsDictionary [num_h5file] .append (curh5file [ "cells"] [j])   

Any help / advice / insight will be greatly appreciated :)

I agree with @Replyclicks Your best bet is to shut down those files which you are not actively using if the PO ssible But if you really want, you can use the command to increase the number of open files available in your process - for details

edit:

You can use to ensure that the file is closed even when there is an error:

  with h5py.file (file, 'r') As curh5file: ... # Do your stuff ... # Continue other actions   

When you do not get out of the "from" block Klte, the file will be automatically closed. If an exception occurs, it will still be closed.

No comments:

Post a Comment