Skip to content

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Oct 3, 2025

Implementation based on a suggestion from @gukoff.

When the environ is mutated during the execution of os.environ.clear() (via another thread, or via destructors of the keys removed), the result can be a non-empty environment after the clear(). This is also the case for the current implementation, so this seems acceptable. The exact results can be different, but this seems unavoidable (in particular in the case of threads).
A variation could be to add super().clear() at the end of the definition of clear() (this would not impact performance complexity)

@picnixz
Copy link
Member

picnixz commented Oct 3, 2025

Actually we already have a PR #139483 so I'm going to close this one as a duplicate. Sorry!

Note: the complexity is still quadratic because unsetenv() rewrites the environment every time it's called. This is unfortunately a drawback from glibc.

@picnixz picnixz closed this Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants