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

Add close() method and with statement support to InputFile #23

Merged
merged 1 commit into from
May 19, 2023
Merged

Add close() method and with statement support to InputFile #23

merged 1 commit into from
May 19, 2023

Conversation

r1cc4rdo
Copy link
Contributor

Fixing two minor annoyances with the library :)

(1) The addition of the close() method allows to programmatically close an open .exr without waiting until the program completion. I often find myself being prevented to operate on files because of dangling, open file descriptors.

(2) The "with" statement support allows to write such as:

with pyexr.open(filepath) as exr_image:
    print(exr_image.get_all().keys())

which closes the open file whatever happens (e.g. should an exception happen).

The addition of the close() method solves the issue of leaving dangling, open file descriptors that prevent filesystem operations on the file during the program lifetime.

The "with" statement support allows to write such as:

``` python
    with pyexr.open(filepath) as exr_image:
        print(exr_image.get_all().keys())
```

Admittedly, it's syntactic sugar, but preferable to forgetting to close() ;)
@tvogels
Copy link
Owner

tvogels commented May 19, 2023

Thanks for your contributions!

@tvogels tvogels merged commit b5dfbb2 into tvogels:master May 19, 2023
@r1cc4rdo r1cc4rdo deleted the patch-1 branch June 3, 2024 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants