lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.

This is weird. dofile (which uses luaL_loadfile) always closes the file
after parsing it (unless the file is stdin). Moreover, I don't see how
a garbage collection would close the file. Unlike files created to
be used by Lua, e.g., by io.open, the file created by loadfile is only
a FILE*; it is not a userdata, and cannot have a finalizer.

As you mentioned Excel, i'm supposing you are using Windows.
If this is the case, you can use Process Explorer utility from
http://www.sysinternals.com/Utilities/ProcessExplorer.html
to track down who keeps the file opened.
It might be explorer.exe (via some shell extension) or
your anti-virus/spyware program and the call to GC just gives more time
to it to finsih its job.
After installing the tool, use Find->Find Handle or Dll menu and
type some part of the file name of lua script. You may click the processes'
names in the list and will be guided to the process owning the handle.
Hope this will help you,
Todor