Julia: Add an option to delete a tempfile when it's reference is garbage collected

Created on 13 Feb 2018  路  1Comment  路  Source: JuliaLang/julia

It can be fairly easily implemented in julia using finalizers.

I think we should not have this as the default behavour, but enable it with a parameter (maybe a keyword arg).
The preferred way to use a tempfile should remain using a do-block.
But when you are making lots of tempfiles (like if using julia for shell-scripting glue),
sometimes nesting do-blocks more than 2 deep becomes unwieldy.
And one is rarely in much of a hurry to delete tempfiles anyway.

Python does this (on by default, option delete=false to disable).
It automatically deleted tempfiles when they are closed, and automatically closes the tempfile when it is garbage collected.

O help wanted

Most helpful comment

Even more useful with temporary directories. I've wanted this recently since written a number of tests that generate a lot of temporary directories with files in them and while noodling around on the REPL, you tend to not clean them up ever. If the GC did it for you, it would be ideal.

>All comments

Even more useful with temporary directories. I've wanted this recently since written a number of tests that generate a lot of temporary directories with files in them and while noodling around on the REPL, you tend to not clean them up ever. If the GC did it for you, it would be ideal.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  路  3Comments

omus picture omus  路  3Comments

arshpreetsingh picture arshpreetsingh  路  3Comments

Keno picture Keno  路  3Comments

felixrehren picture felixrehren  路  3Comments