GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove reference cycle when writing tarfiles · Issue #115256 · python/cpython

Remove reference cycle when writing tarfiles #115256

New issue
Copy link
New issue
Copy link
Closed
Closed
Remove reference cycle when writing tarfiles#115256
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@pan324
pan324
opened on Feb 10, 2024
Issue body actions

Feature or enhancement

Proposal:

The following code keeps a file handle for eternity and even gc.collect does not help.

>>> import tarfile
>>> tarfile.TarFile("archive.tar.gz","w").add("somefile.py")

The culprit is a line that itself says that it is not needed. Indeed, it is never used anywhere. https://github.com/python/cpython/blob/main/Lib/tarfile.py#L2033

Now the example might be a rather bad style, but even a typical use case where a TarFile variable is defined and closed afterwards will also keep some stuff in memory until gc.collect happens due to this line. Removing the line also adds a ResourceWarning to the bad style example which currently does not appear.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-115256: Remove refcycles from tarfile writing #115257

Activity

  1. pan324
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Feb 10, 2024
  2. Eclips4
    added this to Tarfile issues 🗄️on Feb 10, 2024
  3. furkanonder commented on Feb 11, 2024

    @furkanonder
    furkanonder
    on Feb 11, 2024
    Contributor
    More actions

    CC: @encukou

  4. encukou commented on Feb 12, 2024

    @encukou
    encukou
    on Feb 12, 2024
    Member
    More actions

    How can we know that no one is using this member?
    If it needs to be removed, it should be deprecated according to PEP-387.

    @furkanonder Do you have a particular question? I'm not sure why you mentioned me here.

    Reacted by Serhiy Storchaka
  5. serhiy-storchaka commented on Feb 12, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Feb 12, 2024
    Member
    More actions

    When and why this field was added? How it was used in earlier versions? When and why the comment was added?

  6. pan324 commented on Feb 12, 2024

    @pan324
    pan324
    on Feb 12, 2024
    ContributorAuthor
    More actions

    It was not used even when it was introduced. Several other classes at the time also define self.tarfile and use it in methods but TarInfo does not inherit from them. Here's what things looked like 17 years ago:

    cpython/Lib/tarfile.py

    Line 1792 in d8faa36

    tarinfo.tarfile = self

    The comment was added by @vadmium 8 years ago when he extended some of the docstrings. f817a48

    The only public git repo I can find that accesses info.tarfile uses it to find replace symlink infos by their resolved infos: https://github.com/jlevy/instaclone/blob/master/instaclone/archives.py#L65-L75

    It appears that this is not just about lingering handles but may actually corrupt archives as reported here: #78843

  7. vadmium commented on Feb 12, 2024

    @vadmium
    vadmium
    on Feb 12, 2024
    Member
    More actions

    I don't remember why I added the comment. I was probably studying how the module used TarInfo objects, and noticed it setting the tarfile attribute without any documentation or usage of that attribute.

    The attribute itself seems comes from implementing Pax format (c64e402).

    Reacted by pan324
  8. furkanonder commented on Feb 15, 2024

    @furkanonder
    furkanonder
    on Feb 15, 2024
    Contributor
    More actions

    How can we know that no one is using this member? If it needs to be removed, it should be deprecated according to PEP-387.

    @furkanonder Do you have a particular question? I'm not sure why you mentioned me here.

    I've seen you fixing issues with the tarfile module. I tagged you in case you might have an idea about the issue raised here. Sorry if I've disturbed you.

  9. encukou
    added a commit that references this issue on Mar 4, 2024

    gh-115256: Remove refcycles from tarfile writing (GH-115257)

    0dfa7ce
  10. woodruffw
    added a commit that references this issue on Mar 4, 2024

    pythongh-115256: Remove refcycles from tarfile writing (pythonGH-115257)

    21bdf37
  11. adorilson
    added a commit that references this issue on Mar 25, 2024

    pythongh-115256: Remove refcycles from tarfile writing (pythonGH-115257)

    7867353
  12. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-115256: Remove refcycles from tarfile writing (pythonGH-115257)

    6483b32
  13. hugovk commented on Jan 29, 2025

    @hugovk
    hugovk
    on Jan 29, 2025
    Member
    More actions

    Triage: looks like this can be closed, please re-open if there more to do. Thanks!

  14. hugovk
    closed this as completedon Jan 29, 2025
  15. github-project-automation
    moved this to Done in Tarfile issues 🗄️on Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    • Tarfile issues 🗄️
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.