Skip to content

GzipFile leaves GzipFile.myfileobject open in constructor if exception is raised #131492

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

Closed
graingert opened this issue Mar 20, 2025 · 2 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Mar 20, 2025

Bug report

Bug description:

consider the following program, it should raise an ExceptionGroup(..., [ValueError(), ValueError(), ...] but actually it raises OSError: [Errno 24] Too many open files: '/tmp/tmpk8gaprry'

import gzip
import tempfile
import pathlib
import os

def main():
    with tempfile.TemporaryDirectory() as tmp_dir:
        tmp_path = pathlib.Path(tmp_dir)
        zip_path = tmp_path / "some_file.zip"

        exceptions = []
        for i in range(2000):
            try:
                gzip.GzipFile(filename=os.fsdecode(zip_path), mode="w", compresslevel=99)
            except ValueError as e:
                exceptions.append(e)
        if exceptions:
            raise ExceptionGroup("multiple errors creating GzipFiles", exceptions)

main()

CPython versions tested on:

CPython main branch, 3.14, 3.13, 3.12, 3.11

Operating systems tested on:

Linux

Linked PRs

@graingert graingert added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Mar 20, 2025
vstinner added a commit that referenced this issue Mar 20, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 20, 2025
…ructor while owning resources (pythonGH-131462)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 20, 2025
…ructor while owning resources (pythonGH-131462)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this issue Mar 21, 2025
…r while owning resources (GH-131462) (#131518)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this issue Mar 21, 2025
…r while owning resources (GH-131462) (#131519)

(cherry picked from commit ce79274)

Co-authored-by: Thomas Grainger <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@vstinner
Copy link
Member

Fixed by the change ce79274.

@vstinner
Copy link
Member

consider the following program, it should raise an ExceptionGroup(..., [ValueError(), ValueError(), ...] but actually it raises OSError: [Errno 24] Too many open files: '/tmp/tmpk8gaprry'

I confirm that it now raises the ExceptionGroup, rather than failing with "Too many open files". It works as expected.

seehwan pushed a commit to seehwan/cpython that referenced this issue Apr 16, 2025
…ructor while owning resources (python#131462)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants