Skip to content
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

NetCDF tempfile handling broken on windows #24

Closed
dopplershift opened this issue Jun 17, 2015 · 10 comments
Closed

NetCDF tempfile handling broken on windows #24

dopplershift opened this issue Jun 17, 2015 · 10 comments

Comments

@dopplershift
Copy link
Member

When using the NCSS client to open data we saved to a tempfile, we get a RuntimeError due to "Permission denied". I'm guessing Windows doesn't like someone opening the file a second time.

We could try catching the error and opening a different way, but in that case it's a much bigger pain to ensure the file gets deleted. sigh Why can't windows just behave in a unix-like fashion?

This may be obviated once we get the in-memory solution in the netcdf library, but I think it will be awhile after that before it's widely available. Might punt on this until a windows user complains...

@MoonRaker
Copy link
Contributor

I am going to be that Windows user...

Any fixes/workarounds for this yet?

@dopplershift
Copy link
Member Author

Well, the workaround would be to use get_data_raw to get the content of the netcdf file, and save it to a local file (temp or otherwise) yourself.

However, if fixing this would be a boon to your use of siphon, I'm much more inclined to fix it if know I have actual, not hypothetical, user(s) needing it.

@wholmgren
Copy link

@dopplershift See this pvlib-python issue for more info on how we want to use Siphon for solar power forecasts. We can also help address Siphon problems relevant to our work.

@wholmgren
Copy link

also, @dopplershift, many thanks to you and Unidata for developing Siphon!

@dopplershift
Copy link
Member Author

Wow, that looks really cool. I'm glad you're finding Siphon so useful. In general, if you guys just open issues for problems you find (or better yet, PRs for fixes!), that will be great.

For this issue, the big problem is that we're not windows devs on Siphon. I made windows 7 VM, but it was painful. It will definitely go faster if you can find a fix that works for you and make a PR. Otherwise, I can make a pass at a fix, but the testing loop on that will probably be much slower.

@MoonRaker
Copy link
Contributor

I am not sure how you want to proceed but I have made a universal fix within the siphon code that deletes the temporary file upon exit, after setting the NamedTemporaryFile argument "delete" to False. This is also possible to do with less modifications to the Siphon code by deleting the temporary file using dataset.filepath() within our own code but it still requires that the "delete" argument equal False. However, both approaches require that the dataset be closed first.

@dopplershift
Copy link
Member Author

The sounds like the approach I took originally (never committed), until I realized that I could re-open the file (which made the code much cleaner); it's a shame that approach doesn't work on windows.

I'll take a PR with your changes to add the exit handler

@rsignell-usgs
Copy link

Looks like another approach to solving this problem is here:
http://stackoverflow.com/a/15235559
which apparently lets you open the temp file multiple times on windows, so you don't need to set delete=False and then delete the file explicitly.

@dopplershift
Copy link
Member Author

Thanks @rsignell-usgs, that's very helpful.

@dopplershift
Copy link
Member Author

Fixed in #56.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants