sodri126 / netcdf4-python

Automatically exported from code.google.com/p/netcdf4-python
Other
0 stars 0 forks source link

Dangling file references #137

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The underlying netCDF4 function "nc_close" is not being called when open 
Dataset objects are destroyed by Python.

>>> from netCDF4 import Dataset
>>> for i in range(1000):
...  d = Dataset('my_real_file.nc')
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "netCDF4.pyx", line 1314, in netCDF4.Dataset.__init__ (netCDF4.c:14697)
RuntimeError: Too many open files

What version of the product are you using? On what operating system?
 - Version 0.9.9 on 64-bit RHEL6

Original issue reported on code.google.com by rhatters...@gmail.com on 11 Sep 2012 at 1:48

GoogleCodeExporter commented 9 years ago
The close method of the Dataset instance should be used when you're done with 
the file (this calls nc_close).

Original comment by whitaker.jeffrey@gmail.com on 11 Sep 2012 at 5:48

GoogleCodeExporter commented 9 years ago
Yes. I realise calling close() is the documented behaviour. But it would make 
the API more "friendly" to support __del__ for a number of reasons:
 - it would make it more similar to the built-in function "open()"
 - it would reduce the number of things you need to remember to do
 - it would rule out the ability to leave these dangling references - which can't be recovered and closed

Original comment by rhatters...@gmail.com on 12 Sep 2012 at 4:48

GoogleCodeExporter commented 9 years ago
Unfortunately, there's no way I know of to call nc_close from the C extension 
when garbage collector runs.  Adding a __del__ method doesn't do it.  I'll keep 
looking, but right now I don't see a way.

Original comment by whitaker.jeffrey@gmail.com on 12 Sep 2012 at 11:33

GoogleCodeExporter commented 9 years ago
I think I've figured out a way to do this - can you give svn trunk a try and 
let me know if it works for you?

Original comment by whitaker.jeffrey@gmail.com on 16 Sep 2012 at 7:30

GoogleCodeExporter commented 9 years ago

Original comment by whitaker.jeffrey@gmail.com on 12 Mar 2013 at 3:58