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 — Add os.reload_environ() function · Issue #120057 · python/cpython

Add os.reload_environ() function #120057

New issue
Copy link
New issue
Copy link
Closed
Closed
Add os.reload_environ() function#120057
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@vstinner
vstinner
opened on Jun 4, 2024
Issue body actions

Feature or enhancement

When the environment is modified outside Python, os.environ is not updated. I propose adding a new os.environ.refresh() method to manually update os.environ.

Discussion: https://discuss.python.org/t/method-to-refresh-os-environ/54774

Linked PRs

  • gh-120057: Add os.environ.refresh() method #120059
  • gh-120057: Add os.get_user_default_environ() function #120494
  • Revert "gh-120057: Add os.environ.refresh() method (#120059)" #120789
  • Revert "gh-120057: Add os.environ.refresh() method (#120059)" #120790
  • gh-120057: Rename os.environ.refresh() to invalidate_cache() #120808
  • gh-120057: Add os.reload_environ() function #126268
  • gh-120057: add os.reload_environ to __all__ #140763
  • [3.14] gh-120057: add os.reload_environ to __all__ (GH-140763) #140773
Reacted by Agriya Khetarpal, Kirill Podoprigora and W. H. Wang
Reacted by Noam Cohen and sigma67
Reacted by EDM115

Activity

Next
  1. vstinner
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jun 4, 2024
  2. vstinner
    added 2 commits that reference this issue on Jun 4, 2024

    pythongh-120057: Add os.environ.refresh() method

    50447f4

    pythongh-120057: Add os.environ.refresh() method

    df06534
  3. eryksun commented on Jun 4, 2024

    @eryksun
    eryksun
    on Jun 4, 2024
    Contributor
    More actions

    Note that on Windows the C runtime's Unicode and multibyte environments -- _wenviron and _environ -- can get out of sync with the process environment -- GetEnvironmentStringsW() -- due to code that directly calls WinAPI SetEnvironmentVariableW(). It's possible to implement a function to fresh the C environment on Windows, which unsets the variables in _wenviron and sets the variables from GetEnvironmentStringsW(), but that's probably not something that the Python runtime needs to worry about.

  4. vstinner
    added a commit that references this issue on Jun 5, 2024

    pythongh-120057: Add os.environ.refresh() method

    fbfb02a
  5. vstinner commented on Jun 5, 2024

    @vstinner
    vstinner
    on Jun 5, 2024
    MemberAuthor
    More actions

    but that's probably not something that the Python runtime needs to worry about

    As soon as there are different "caches", it's hard to keep everything in sync and consistent :-(

  6. erlend-aasland commented on Jun 5, 2024

    @erlend-aasland
    erlend-aasland
    on Jun 5, 2024
    Contributor
    More actions

    I'm not sure if this is a good idea. I suspect it will be a hard feature to get right, and as noted in the forum discussion, most beginners will misunderstand the feature.

  7. vstinner commented on Jun 5, 2024

    @vstinner
    vstinner
    on Jun 5, 2024
    MemberAuthor
    More actions

    I suspect it will be a hard feature to get right

    Would you mind to elaborate?

  8. vstinner commented on Jun 5, 2024

    @vstinner
    vstinner
    on Jun 5, 2024
    MemberAuthor
    More actions

    and as noted in the forum discussion, most beginners will misunderstand the feature.

    I added "in the same process" to reduce misunderstanding.

    Reacted by Erlend E. Aasland
  9. picnixz commented on Jun 5, 2024

    @picnixz
    picnixz
    on Jun 5, 2024
    Member
    More actions

    FYI, there was this issue: #119737 (so you may want to close it to avoid duplicates)

    Reacted by Erlend E. Aasland
  10. vstinner commented on Jun 5, 2024

    @vstinner
    vstinner
    on Jun 5, 2024
    MemberAuthor
    More actions

    I closed issue #119737 as a duplicate of this issue.

  11. vstinner
    added a commit that references this issue on Jun 10, 2024

    gh-120057: Add os.environ.refresh() method (#120059)

    7aff2de
  12. vstinner commented on Jun 11, 2024

    @vstinner
    vstinner
    on Jun 11, 2024
    MemberAuthor
    More actions

    Implemented by the commit 7aff2de.

  13. vstinner
    closed this as completedon Jun 11, 2024
  14. WolfDWyc commented on Jun 11, 2024

    @WolfDWyc
    WolfDWyc
    on Jun 11, 2024
    More actions

    @vstinner

    As I noted in the discourse thread, and was mentioned in the comment on the PR, I still feel like this name will be confusing for new users, even with docs clarifying it. Can we maybe re-discuss this? Or at least choose another name?

    Should we continue here or in the discourse thread?

    Reacted by Erlend E. Aasland
  15. 20 remaining items

  16. ncoghlan commented on Oct 31, 2024

    @ncoghlan
    ncoghlan
    on Oct 31, 2024
    Contributor
    More actions

    I think @zooba's point was that this function doesn't reload the system wide environment variable settings into the running application process, which os.reload_environment() could be taken to mean.

    That misreading doesn't seem particularly likely to me though, and the fact this operation reloads both os.environ and os.environb (not just os.environ) makes me wary of the shorter os.reload_environ() name (it feels misleading to me in the same way that the os.environ.refresh() spelling is misleading).

  17. zooba commented on Oct 31, 2024

    @zooba
    zooba
    on Oct 31, 2024
    Member
    More actions

    I can't reasonably see os.reload_environ() implying that os.environb wouldn't also be reloaded. Certainly not as much as I can see someone thinking that os.reload_environment() implies something other than "os.environ will be reloaded".

    Whereas os.environ.refresh() could quite reasonably be assumed to have no impact on os.environb. So I think that's another argument in favour of the module-level function.

    Perhaps os.reload_environs() feels more comfortable for covering both os.environ and os.environb? I don't have a strong preference about the s. My main concern is still the same as at the start - this function doesn't impact the (generic) environment of the process at all, it only affects what is contained in Python's cache of the environment, otherwise known as os.environ.

  18. vstinner
    added a commit that references this issue on Nov 1, 2024

    pythongh-120057: Add os.reload_environ() function

    0a00444
  19. vstinner commented on Nov 1, 2024

    @vstinner
    vstinner
    on Nov 1, 2024
    MemberAuthor
    More actions

    I created PR gh-126268 to replace the os.environ.refresh() method with a new os.reload_environ() function.

    IMO reload_environ() is a good name since it reminds os.environ. I don't think that we should bother with the fact that os.environb is also reloaded to name the function. And reload_environment() is too long :-)

  20. picnixz
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Nov 1, 2024
  21. vstinner
    added a commit that references this issue on Nov 5, 2024

    gh-120057: Add os.reload_environ() function (#126268)

    4a0d574
  22. vstinner
    changed the title [-]Add os.environ.refresh() method[/-] [+]Add os.reload_environ() function[/+] on Nov 5, 2024
  23. vstinner commented on Nov 5, 2024

    @vstinner
    vstinner
    on Nov 5, 2024
    MemberAuthor
    More actions

    I created PR #126268 to replace the os.environ.refresh() method with a new os.reload_environ() function.

    Done: I merged the PR. I close the issue.

  24. vstinner
    closed this as completedon Nov 5, 2024
  25. picnixz
    added a commit that references this issue on Dec 8, 2024

    pythongh-120057: Add os.reload_environ() function (python#126268)

    610da8f
  26. ebonnal
    added a commit that references this issue on Jan 12, 2025

    pythongh-120057: Add os.reload_environ() function (python#126268)

    1960b30
  27. AlexWaygood
    added a commit that references this issue on Oct 29, 2025

    gh-120057: add `os.reload_environ` to `__all__` (#140763)

    b85e10f
  28. miss-islington
    added a commit that references this issue on Oct 29, 2025

    pythongh-120057: add `os.reload_environ` to `__all__` (pythonGH-140763)

    37027ce
  29. AlexWaygood
    added a commit that references this issue on Oct 29, 2025

    [3.14] gh-120057: add `os.reload_environ` to `__all__` (GH-140763) (#…

    6e70c75
  30. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythongh-120057: add `os.reload_environ` to `__all__` (python#140763)

    2525c6c
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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      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.