-
Notifications
You must be signed in to change notification settings - Fork 11
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
Improve the documentation for Tempfile.create and recommend Tempfile.open instead #5
Conversation
BTW I was trying to see if finalizers always run before the process exits, and it seems not even on CRuby: Or maybe there is something wrong with my usage of a finalizer?
=> the finalizer callable needs to accept one argument, which is the object id
And when using
My impression is finalizers are not reliable at all, and might not even run. And I think this is even more the case on TruffleRuby/JRuby. On TruffleRuby we tried to run finalizers for live objects on exit, but that failed in various ways because finalizer procs can depend on each other and then the order to run them matters. Also considering that CRuby uses a conservative GC, it's not impossible for a random (e.g., |
As far as a user needs temporary file removal by GC, we should not deprecate |
@akr I think there is no case where someone actually wants to remove the file by GC, it's undeterministic, leads to weird CI transient failures (that's why both test-all and test-spec explicitly check against it) and generally unreliable. Same thing as relying on File.new being closed by GC, it's a bad idea (and can run out of open fds). But anyway, this PR does not deprecate the method, only recommends |
open-uri without block can return a tempfile. GC based tempfile removal is actually used. So, the logic, discourage Tempfile.open because GC based tempfile removal is not used, is too naive. |
Not because it's not used, but because it's unreliable, inefficient and very rarely needed. |
eef293a
to
13325ee
Compare
# | ||
# Tempfile.open is still appropriate if you need the Tempfile to be unlinked | ||
# by a finalizer and you cannot explicitly know where in the program the | ||
# Tempfile can be unlinked safely. |
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.
@akr I added this paragraph and changed above exists only
=> exists mostly
. Sounds good?
It seems fine. I found that the document of Tempfile.new is also problematic, though. |
13325ee
to
3b74f41
Compare
3b74f41
to
8bac025
Compare
See https://bugs.ruby-lang.org/issues/17144
Follow-up of #4
My understanding is nobody should use Tempfile.open and it only exists for compatibility.
Probably we should consider issuing a deprecation warning (will file an issue on https://bugs.ruby-lang.org for that).
cc @hsbt @akr @jeremyevans