[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: The dofile does not unlock the file until GC
- From: "Alexander Gladysh" <agladysh@...>
- Date: Thu, 3 Aug 2006 20:33:24 +0400
Hi, all!
(WinXP SP2, Lua 5.1.1)
I'm writing small utility, that takes some number of lua files,
pregenerated by Excel script, and merges them into single file, doing
some postprocessing. This utility should delete input files before it
exits.
For example (untested illustrational code):
-- Sample input file looks like:
-- return { table_data };
--
local result = { };
for i = 1,9 do
merge_to_result(result, dofile("filename_" .. i .. ".lua")
end
-- ... (*)
for i = 1,9 do
assert(os.remove("filename_" .. i .. ".lua"))
end
The call to os.remove() fails, reporting the file is locked by
someprocess. If I add call to collectgarbage("collect") on line (*),
os.remove() succeeds. Looks like dofile() keeps file open until GC.
It is somewhat inconvenient. Is it a bug or intentional feature?
Thanks in advance,
Alexander.