Done:
https://github.com/PyTables/PyTables/issues/159
I did not understand how to attach a file to a github issue.
Anyway, I produced a pastebin address and attach the unittest here.

Regards,
Daniele

Il 25/06/2012 09:35, Antonio Valentino ha scritto:
Ciao Daniele,

Il giorno Mon, 25 Jun 2012 09:17:00 +0200
Mythsmith <s...@modena1.it> ha scritto:

Hi Anthony,
Shouldn't the close() method also clear the cache? I think a file
should be either opened or closed... Should I file a bug report?
Best regards,
Daniele

The close method also remover the file from the cache if there are no
more references to it

https://github.com/PyTables/PyTables/blob/6fccb7495ba1bc758c7b04960fe1cd392abe9b96/tables/file.py#L2098

Anyway yes, if you have some problem with the file caching system
please file a bug report on github.

Of course test scripts or patches are very welcome.

ciao

Il 21/06/2012 19:23, Anthony Scopatz ha scritto:
Hi Daniele,

This is probably because of the way PyTables caches its file
objects. As a temporary work around, why don't you try clearing the
cache or at least removing this file.  The cache is just a
dictionary and it is located at "tables.file._open_files".   ie try:

tables.file._open_files.clear()
-or-
del tables.file._open_files.pop["touch.h5"]

Be Well
Anthony

On Thu, Jun 21, 2012 at 10:43 AM, Mythsmith <s...@modena1.it
<mailto:s...@modena1.it>> wrote:

     Hi,
     I noticed that if I open an erroneous file (eg: empty), then it
     seems not possible to completely close it and reopen the same
     path, even if a valid file was created in the meanwhile.
     The error is:
     ValueError: The file 'touch.h5' is already opened.  Please close
     it before reopening in write mode.

     You find a complete example attached.

     Regards,
     daniele




#!/usr/bin/python
"""This test checks that opening an erroneous file leaves a clean cache state.
Eg: a correct file can later be opened even if it is in the same path"""

import unittest
import tables
import os
wpath='err_opening.h5'

class ClosingErroneousFiles(unittest.TestCase):
	
	def setUp(self):
		"""Touch a non-hdf5 file"""
		f=open(wpath,'w')
		f.write('ciao')
		f.close()
		
	def tearDown(self):
		"""Delete the working file."""
		os.remove(wpath)
		
	def test01_Opening(self):
		"""Tests the opening of an erroneous file"""
		try:
			t=tables.openFile(wpath,mode='r')
			self.fail("Opening an erroneous file should raise an exception!")
			s=t.__str__()
			t.close()
		except:
			pass
		
	def test02_ReOpenCorrect(self):
		"""Place a correct hdf5 file in the same path as the erroneous one, and try to open again"""
		#Create a correct file
		t=tables.openFile('ok.h5',mode='w')
		t.close()
		# Remove old file
		os.remove(wpath)
		# Place correct file in old path
		os.rename('ok.h5', wpath)
		# Try opening again
		t=tables.openFile(wpath,mode='w')
		s=t.__str__()
		print s		

if __name__ == '__main__':
	unittest.main()
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to