Skip to content

platform.node() does not return the latest hostname value #122525

Description

@kashav

Bug report

Bug description:

I think it's because of how cache is implemented for the uname() helper: https://github.com/python/cpython/blob/5377f55b4e022041b7b57b5489c66c9b3c046c7e/Lib/platform.py#L890-L905.\

Given socket.gethostname() exists as well and respects the latest hostname value, maybe this issue is wontfix. Thought I would file it anyhow.

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jul 31, 2024
  2. kashav commented on Jul 31, 2024

    @kashav
    Author

    STR in case they help:

    import platform, socket
    print(platform.node(), socket.gethostname())
    # update the machine's hostname (for macOS it's Settings -> General -> Sharing)
    print(platform.node(), socket.gethostname()) # notice that this is reporting the old value
  3. ZeroIntensity commented on Jul 31, 2024

    @ZeroIntensity
    Member

    I'm guessing this is somewhat intentional. platform.node() is equivalent platform.uname().node, and uname() has a cached result.

  4. kashav commented on Jul 31, 2024

    @kashav
    Author

    Oh I hadn’t noticed that there’s a platform.uname() method as well. I guess this is somewhat intentional then. It would help to document that uname and its dependents rely on a cached result that might be knowingly stale.

  5. picnixz commented on Aug 1, 2024

    @picnixz
    Member

    Most of the functions in platform are using cached values. However, I somewhat think that we should have a mean to invalidate this cache. I'll prepare a PR for that.

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-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions