Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclosed file object #404

Open
RyanTerb opened this issue May 2, 2023 · 3 comments
Open

Unclosed file object #404

RyanTerb opened this issue May 2, 2023 · 3 comments
Labels
in integration merged into integration branch

Comments

@RyanTerb
Copy link

RyanTerb commented May 2, 2023

Noticed with sarpy 1.3.30 that the sicd_writer is throwing a warning:

/usr/local/lib/python3.10/site-packages/sarpy/io/general/nitf.py:4168: ResourceWarning: unclosed file <_io.BufferedWriter name=

It looks like a file object is not being close properly and python is unhappy. Based on the this code, it might not be triggering the __del__ operator that closes the file object, link.

The following code removed the warning for me. I had to explicitly call flush though.

  writer = sicd.SICDWriter(
      file_object=filename,
      sicd_meta=SICDType(**sicd_data.__dict__),
      check_existence=False
  )

  writer.write(complex_image, (0, 0))
  writer.flush()
  writer._file_object.close()
  writer.close()

If I'm incorrectly writing a sicd_file or closing, please advise.

Thanks !

@Darder
Copy link
Contributor

Darder commented May 3, 2023

Did you not run into this problem before with earlier versions of SARPY?

@RyanTerb
Copy link
Author

RyanTerb commented May 8, 2023

I have not.

@pressler-vsc
Copy link
Collaborator

@RyanTerb, thanks for writing this up. This does seem to be a bug in the NITFWriter introduced in the 1.3.30 refactor and is also an issue with the CPHDWriter. This should be addressed in #476.

@pressler-vsc pressler-vsc added the in integration merged into integration branch label Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in integration merged into integration branch
Projects
None yet
Development

No branches or pull requests

3 participants