@@ -193,10 +193,6 @@ process and user.
193193 to the environment made after this time are not reflected in :data: `os.environ `,
194194 except for changes made by modifying :data: `os.environ ` directly.
195195
196- The :meth: `!os.environ.refresh ` method updates :data: `os.environ ` with
197- changes to the environment made by :func: `os.putenv `, by
198- :func: `os.unsetenv `, or made outside Python in the same process.
199-
200196 This mapping may be used to modify the environment as well as query the
201197 environment. :func: `putenv ` will be called automatically when the mapping
202198 is modified.
@@ -226,12 +222,13 @@ process and user.
226222 :data: `os.environ `, and when one of the :meth: `pop ` or :meth: `clear ` methods is
227223 called.
228224
225+ .. seealso ::
226+
227+ The :func: `os.reload_environ ` function.
228+
229229 .. versionchanged :: 3.9
230230 Updated to support :pep: `584 `'s merge (``| ``) and update (``|= ``) operators.
231231
232- .. versionchanged :: 3.14
233- Added the :meth: `!os.environ.refresh ` method.
234-
235232
236233.. data :: environb
237234
@@ -249,6 +246,24 @@ process and user.
249246 Updated to support :pep: `584 `'s merge (``| ``) and update (``|= ``) operators.
250247
251248
249+ .. function :: reload_environ()
250+
251+ The :data: `os.environ ` and :data: `os.environb ` mappings are a cache of
252+ environment variables at the time that Python started.
253+ As such, changes to the current process environment are not reflected
254+ if made outside Python, or by :func: `os.putenv ` or :func: `os.unsetenv `.
255+ Use :func: `!os.reload_environ ` to update :data: `os.environ ` and :data: `os.environb `
256+ with any such changes to the current process environment.
257+
258+ .. warning ::
259+ This function is not thread-safe. Calling it while the environment is
260+ being modified in an other thread is an undefined behavior. Reading from
261+ :data: `os.environ ` or :data: `os.environb `, or calling :func: `os.getenv `
262+ while reloading, may return an empty result.
263+
264+ .. versionadded :: next
265+
266+
252267.. function :: chdir(path)
253268 fchdir(fd)
254269 getcwd()
@@ -568,7 +583,7 @@ process and user.
568583 of :data: `os.environ `. This also applies to :func: `getenv ` and :func: `getenvb `, which
569584 respectively use :data: `os.environ ` and :data: `os.environb ` in their implementations.
570585
571- See also the :data : `os.environ.refresh() <os.environ> ` method .
586+ See also the :func : `os.reload_environ ` function .
572587
573588 .. note ::
574589
@@ -818,7 +833,7 @@ process and user.
818833 don't update :data: `os.environ `, so it is actually preferable to delete items of
819834 :data: `os.environ `.
820835
821- See also the :data : `os.environ.refresh() <os.environ> ` method .
836+ See also the :func : `os.reload_environ ` function .
822837
823838 .. audit-event :: os.unsetenv key os.unsetenv
824839
0 commit comments