-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: ncss netcdf temp file permission error on Windows #56
Conversation
@@ -2,6 +2,8 @@ | |||
from io import BytesIO | |||
|
|||
import numpy as np | |||
from os import remove | |||
import atexit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For cleanliness, can you move atexit
import to the first line, and the from os
to just under from io
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. What is the reasoning? Just for my future reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We group the imports (based partially on PEP8) by standard library (first full import, then partial import), then third party, then our own; arranged alphabetically. Doing it consistently makes it easy to find stuff when you have quite a few imports.
Awesome, thanks for the contribution. Mostly just a bunch of little (picky) stuff. This looks identical to what I had originally, before I "discovered" the cleaner approach on *nix. What I wonder is whether we should just enable this method on windows and stick with the original method on *nix. @lesserwhirls any opinions here? |
Thanks for the comments, I appreciate the input for sure. Either way is fine with me. |
|
I think I like the approach described at http://stackoverflow.com/a/15235559 (and mentioned in #24) better. Any thoughts? I'm willing to take a pass at implementing that approach, though it might be a week before I can do so; feel free to try it yourself if you're so inclined. Either way, if you could test it and see if it actually works on Windows, that would be very helpful. |
It seems like a cleaner approach. I'll give it a go. At first pass though the entire implementation of the temporaryfile might have to look different otherwise it will require modifying the netCDF library since that is where the second open operation takes place. |
paperbag moment You're right, I didn't think things through. We can go with your original approach, though I'd like to leave the original code for OSX/Linux and only use the |
6a60475
to
556e456
Compare
I have updated so that the usage for OSX/Linux is the same as before and only the Windows temporary file is handled with atexit. |
|
Overall, I think we're almost there. There are some pep8 issues picked up by pylint:
Also need to address the remaining inline comments. The actual test failures are caused by a new version of |
def deletetempfile(fname): | ||
try: | ||
remove(fname) | ||
except PermissionError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PermissionError
it turns out is >= Python 3.3. I don't mind dropping Python 3.2, but I'm not quite prepared to drop Python 2.7. Since PermissionError
is a subclass of OSError
, can you use that instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be fine. I have also taken care of the inline pep8 issues.
1 similar comment
This looks good. Thanks for going around with me on it. |
Fix: ncss netcdf temp file permission error on Windows
I appreciate your patience and helping me work through it. |
These changes were made in response to the inability of python to open a temporary file twice on Windows systems, Permission Denied error, thus preventing ncss.get_data() queries in Siphon. Issue #24 NetCDF tempfile handling broken on windows.
The temporary file is now persistent but is then deleted at exit. The temporary file will only be removed if .close() method is called on the netCDF Dataset. With this fix the error message disappears and all nosetests pass. It has not been tested on Linux/Unix.
Siphon v0.3.1
Code that reproduces the error (also fails 2 nosetests; test_netcdf_point, test_netcdf4_point):
best_gfs = TDSCatalog('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p5deg/catalog.xml?dataset=grib/NCEP/GFS/Global_0p5deg/Best')
best_gfs.datasets
best_ds = list(best_gfs.datasets.values())[0]
best_ds.access_urls
ncss = NCSS(best_ds.access_urls['NetcdfSubset'])
query = ncss.query()
query.lonlat_point(-110.9, 32.2).vertical_level(100000).time_range(start, end)
query.variables('Temperature_isobaric').accept('netcdf')
data = ncss.get_data(query)
...line 351, in read_netcdf
return Dataset(tmp_file.name, 'r')
File "netCDF4_netCDF4.pyx", line 1616, in netCDF4._netCDF4.Dataset.init (netCDF4_netCDF4.c:9989)
RuntimeError: Permission denied