8000 platform.node() does not return the latest hostname value · Issue #122525 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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
kashav opened this issue Jul 31, 2024 · 4 comments
Closed

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

kashav opened this issue Jul 31, 2024 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@kashav
Copy link
kashav commented Jul 31, 2024

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

@kashav kashav added the type-bug An unexpected behavior, bug, or error label Jul 31, 2024
@kashav
Copy link
Author
kashav commented Jul 31, 2024

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

@ZeroIntensity
Copy link
Member

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

@kashav
Copy link
Author
kashav commented Jul 31, 2024

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.

@picnixz
Copy link
Member
picnixz commented Aug 1, 2024

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
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants
0