-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
numpy.ma.dump and np.ma.load fail to close the files that they open #10045
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
Comments
Which file is this code located in? |
|
Sorry for my ignorance, I've just started contributing, but I'm confused as to whether we can just add F.close() after we have opened the file. It seems like we cannot since we return F after, so we don't want to close it. Am I thinking about this correctly? |
You are thinking about it correctly, but it's easy enough to put in an
All told, it's probably not a big deal as in all Python implementations under which numpy runs (that I am aware of), when the function returns, |
Why on earth do any of these exist?
It seems pretty obvious to me that exposing a slightly-tweaked Given that this is already broken on py3, I vote we leave it broken and simply add
|
On CPython the opened file object is cleaned up immediately, but other implementations like PyPy generally only guarantee that the file object is cleaned up "eventually". (They don't do refcounting, so all deallocations wait until a GC pass happens.) On such implementations, you can have problems if you e.g. call It's not exactly a showstopper urgent bug, but it would be better to explicitly close the file here. |
Oh, it's actually |
Yep, |
Where do you see that? I get:
|
The method is in the public API and has not been marked deprecated. On CPython if you use it with warnings enabled you get a ResourceWarning:
The fix is trivial (close the file if you opened it) so it would be great if we could add the fix for the next patch release. Shall I make a pull request for this? The example above from @rkern seems fine to me (I don't think Regarding the comment above about it wrapping pickle with no extra wrapping, it does let you dump to a filename rather than a file handle, which can be handy when you are debugging. I have no objection to these functions being given a DeprecationWarning for v1.14 if that's where people want to go,although I am guessing there should be a wider discussion than on this issue? |
Apologies, I was testing This is super confusing, because |
Not in python 3, it doesn't, thanks to #5491. So on that basis, no one is using that featu 8000 re except on python 2.7, which is approaching EOL.
|
Ah, I see. Why was Why is this not a good solution?
|
I'm a bit shocked that it's taken 3 years to not add the PS We are using python3. |
@timj: I've o 9E4A f the opinion that if it's been broken since the beginning of time for python 3, and the existance of the function is unjustifiable, we should leave it broken, but with a clearer error message - this is a great time to remove it from the API in anticipation of the Py3 only version of numpy. |
I guess there could be people using it on py3 and explicitly passing in a
pre-opened binary file? I do like the idea of getting rid of it though if
we can – every extra method on ndarray makes more work for everyone
implementing a new duck-array type.
…On Nov 19, 2017 2:19 PM, "Eric Wieser" ***@***.***> wrote:
@timj <https://github.com/timj>: I've of the opinion that if it's been
broken since the beginning of time for python 3, and the existance of the
function is unjustifiable, we should leave it broken, but with a clearer
error message - this is a great time to remove it from the API in
anticipation of the Py3 only version of numpy.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#10045 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAlOaNX0WbmVMqjeJvsQ7YVkEVhwianFks5s4Kl8gaJpZM4QiavD>
.
|
numpy 1.13.1 dump fails to close the file that it opens (as a unit test in our code reported). The code appears to be as follows, which is clearly not closing the file it might open:
The text was updated successfully, but these errors were encountered: