A Tuesday 03 February 2009, afog...@princeton.com escrigué:
> Francesc Alted wrote:
> > At least each open node keeps a reference to the File object.  So,
> > in order to remove the File object you must close the nodes that
> > reference to them.  See the File.close() for an example on how to
> > do this.  I don't know if I have addressed your issue, but if not,
> > please tell me.
>
> Well, let me start with a simple problem.  If I open up a file, and
> then don't explicitly close it, when I quit Python I get a "Closing
> remaining open files:" and then a list of all the files.  Part of the
> problem is these refcounts.  If the only reference was the file
> object, I could be at least be assured that the file objects used in
> a more constrained scope (inside classes or functions) would be
> garbage collected, but that's definitely not the case.
>
>  >>> import tables, sys, gc
>  >>> gc.set_debug(gc.DEBUG_LEAK)
>  >>> gc.collect()
>
> 0
>
>  >>> fyle1 = tables.openFile("Foo.h5")
>  >>> sys.getrefcount(fyle1)
>
> 6
>
>  >>> del fyle1
>  >>> gc.collect()
>
> 0
>
>  >>> exit()
>
> Closing remaining open files: Foo.h5... done
>
> (I've changed the name of the file to the much smaller "Foo.h5"
> rather than the full path.)
>
> Something is keeping that file object open, and I don't understand
> what. It's obviously not just a reference cycle, because it's not
> showing up in the garbage.

Ah, I think I understand now what you are after.  PyTables detects that 
there are opened files because they are kept on a dictionary 
(`_open_files`) in the `file` module.  A function (`close_open_files`) 
is registered through the `atexit` module, and if it detects entries in 
the `_open_files` dictionary, it proceeds to close them before exiting.

So, if what you want is to avoid closing the file after a ``del 
fileh``operation, it should be enough to "unregister" the file first.  
Something like:

import tables
fyle1 = tables.openFile("Foo.h5")
del tables.file._open_files[fyle1]
del fyle1

would work.

Hope this helps,

-- 
Francesc Alted

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to