Skip to content

fci_l1c_nc reader can't properly release file handle after reading under Windows #3263

@yukaribbba

Description

@yukaribbba

Describe the bug
Just like the title said. Those nc files are still in lock so I can't move or delete them except for the last TRAIL part. Actually I'm not sure if it's a bug or just another nasty file handling problem in windows.

To Reproduce
Some ordinary satpy lines

scn = Scene(files=files)
scn.load([...])
scn.resample(...)
scn.save_dataset(...)

Temporary Solution
After done with your Scene object, try these lines:

for reader in scn._readers.values():
    fhd = getattr(reader, "file_handlers", {})
    for fhs in fhd.values():
        for fh in fhs:
            if hasattr(fh, "close"):
                fh.close()
            else:
                h = getattr(fh, "file_handle", None)
                if h is not None:
                    try:
                        h.close()
                    except Exception:
                        pass
                    fh.file_handle = None

They'll get every possible file handler in your Scene and close it so the files could be release. They work in my case at least.

Expected behavior
The file handles should be closed without further lines.

Environment Info:

  • OS: Windows 11 24h2
  • Satpy Version: 0.58

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions