Skip to content

ResourceWarning: unclosed file #103

@josteinl

Description

@josteinl

Using the artifacts-keyring package I now get the following warning:

uv\tools\keyring\Lib\site-packages\artifacts_keyring\plugin.py:114: ResourceWarning: unclosed file <_io.BufferedWriter name=4>
  username, password = self._get_credentials_from_credential_provider(url, is_retry=False)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Examining the code in the method _get_credentials_from_credential_provider(), it appears that stdin is opened, never used, and never closed.

Suggest changing:

artifacts-keyring/src/artifacts_keyring/plugin.py

@@ 154,1
-        stdin=subprocess.PIPE,
+        stdin=subprocess.DEVNULL,

I also think you can use Popen as a context manager, so the pipes are automatically closed:

with Popen(...) as proc:
    ....

I am not an expert on this, and don't know all your requirements for supported versions/platforms/architectures, so this may not be easy to fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions