This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.steinmeyer
Recipients christian.steinmeyer
Date 2021-07-14.14:48:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626274107.84.0.867808492454.issue44638@roundup.psfhosted.org>
In-reply-to
Content
When executing the code below with the attached zip file (or any other that has one or more files directly at root level), I get a "ValueError: seek of closed file". It seems, the zipfile handle being part of the `TestClass` instance is being closed, when the `zipfile.Path` is garbage collected, when it is no longer referenced. Since `zipfile.Path` even takes a `zipfile.Zipfile` as an argument, I don't think it is intended? It surprised me at least.


```
import zipfile


class TestClass:
    def __init__(self, path):
        self.zip_file = zipfile.ZipFile(path)

    def iter_dir(self):
        return [each.name for each in zipfile.Path(self.zip_file).iterdir()]

    def read(self, filename):
        with self.zip_file.open(filename) as file:
            print(file.read())

root = "zipfile.zip"
test = TestClass(root)
files = test.iter_dir()
test.read(files[0])
```
History
Date User Action Args
2021-07-14 14:48:27christian.steinmeyersetrecipients: + christian.steinmeyer
2021-07-14 14:48:27christian.steinmeyersetmessageid: <1626274107.84.0.867808492454.issue44638@roundup.psfhosted.org>
2021-07-14 14:48:27christian.steinmeyerlinkissue44638 messages
2021-07-14 14:48:27christian.steinmeyercreate