当我创建临时 File/Directory 时,它何时会被删除?
When I create a Temporary File/Directory, when will it be removed?
Julia 包含一个 number of methods 用于制作临时文件和目录。
我相当大量地使用它们(和 /dev/shm
),以推断真正想要使用实际文件的库(JLD/HDF5,和 OpenStack Swift) .
我一直假设当它们指向名称的指针上的终结器被调用时,它们会被删除。
但是在离开 julia 之后,他们似乎都还在那里。
会linux删除它们吗?
如果应用程序没有自行清理,OS 最终会删除文件。删除临时文件时取决于系统设置。例如,它可以在启动时或每晚(通过 cron 作业)或其他方式发生。
您可能正在寻找什么,
考虑到它们没有被删除,这让您感到惊讶,因为它们超出了范围,因为 mktemp
的 do 块版本。
在非常 documentation you linked.
mktemp(f::Function[, parent=tempdir()])
Apply the function f to the result of mktemp(parent) and remove the temporary file upon completion.
mktempdir(f::Function[, parent=tempdir()])
Apply the function f to the result of mktempdir(parent) and remove the temporary directory upon completion.
你可以像这样使用:
mktempdir("/dev/shm") do tdir
fname = joinpath(tdir, name)
#Do some things with your new temp filename `fname` in your tempdir `tdir`
end
#the directory referenced by `tdir`, and `fname`, have now been deleted.
Julia 包含一个 number of methods 用于制作临时文件和目录。
我相当大量地使用它们(和 /dev/shm
),以推断真正想要使用实际文件的库(JLD/HDF5,和 OpenStack Swift) .
我一直假设当它们指向名称的指针上的终结器被调用时,它们会被删除。 但是在离开 julia 之后,他们似乎都还在那里。
会linux删除它们吗?
如果应用程序没有自行清理,OS 最终会删除文件。删除临时文件时取决于系统设置。例如,它可以在启动时或每晚(通过 cron 作业)或其他方式发生。
您可能正在寻找什么,
考虑到它们没有被删除,这让您感到惊讶,因为它们超出了范围,因为 mktemp
的 do 块版本。
在非常 documentation you linked.
mktemp(f::Function[, parent=tempdir()])
Apply the function f to the result of mktemp(parent) and remove the temporary file upon completion.
mktempdir(f::Function[, parent=tempdir()])
Apply the function f to the result of mktempdir(parent) and remove the temporary directory upon completion.
你可以像这样使用:
mktempdir("/dev/shm") do tdir
fname = joinpath(tdir, name)
#Do some things with your new temp filename `fname` in your tempdir `tdir`
end
#the directory referenced by `tdir`, and `fname`, have now been deleted.