Tempfile broken in Ruby 1.9.1?

I’ve been using Tempfile to create ~ 6 files of plot data. However,
all but the last two files were unlinked as the new ones were created,
so at the end, I only had two files, not six. I tried several
combinations - closing the file and re-opening in “r+” mode, NOT
closing the file – nothing made a difference.

I’m pretty sure the Tempfile contract is that the files are to stick
around until the process exits, but my Ruby process was no exiting.

I saw ruby-core discussions about a possible Tempfile bug in 1.9.1,
but that appeared to only apply when calling unlink().

So: Is this a known problem?

  • If so, I can work around it.
  • If not, I can create a minimal test case to demonstrate the problem.
    (Would that be useful?)

Let me know…

  • rdp

P.S.:

bash-3.2$ ruby --version
ruby 1.9.1p376 (2009-12-07 revision 26041) [powerpc-darwin9.8.0]
bash-3.2$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.5.8
BuildVersion: 9L30

I saw ruby-core discussions about a possible Tempfile bug in 1.9.1,
but that appeared to only apply when calling unlink().

So: Is this a known problem?

Not sure. Only thing related appears to be
http://redmine.ruby-lang.org/issues/show/1494

Robert P. [email protected] wrote:

I’ve been using Tempfile to create ~ 6 files of plot data. However,
all but the last two files were unlinked as the new ones were created,
so at the end, I only had two files, not six. I tried several
combinations - closing the file and re-opening in “r+” mode, NOT
closing the file – nothing made a difference.

I’m pretty sure the Tempfile contract is that the files are to stick
around until the process exits, but my Ruby process was no exiting.

Hi Robert,

No, the contract is that Tempfiles exist until there are no longer
references to the objects that refer to them. Once there are no more
references, the GC can reap and delete them when the finalizers are
called.

I saw ruby-core discussions about a possible Tempfile bug in 1.9.1,
but that appeared to only apply when calling unlink().

So: Is this a known problem?

  • If so, I can work around it.

Just keep references around to the tempfiles until you no longer
need them.