Skip to content

File not closed properly after usage on Windows #43673

Open
@abx78

Description

@abx78

Even on basic scenarios, a file on windows does not get released correctly by the process

data = open(file_name) do f
    read(f, String)
end

After this, the Computer Management on Windows will show the file in the Open Files for a while.

This can help temporarily fixing the issue

function open(f, file)
    io = open(file)
    handle = Libc._get_osfhandle(RawFD(fd(io)))
    try
        return f(io)
    finally
        close(io)
        ccall(:CloseHandle, stdcall, Cint, (Ptr{Cvoid},), handle)
    end
end

julia> versioninfo()
Julia Version 1.6.4
Commit 35f0c91 (2021-11-19 03:54 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Xeon(R) Gold 6242 CPU @ 2.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake-avx512)

Metadata

Metadata

Assignees

No one assigned

    Labels

    filesystemUnderlying file system and functions that use itneeds more infoClarification or a reproducible example is requiredsystem:windowsAffects only Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions