Python Glossary Русский

Python 3.14+osfunction

os.reload_environ()

os — environment

Reloads the process environment into os.environ/os.environb — e.g. after os.putenv() or changes made outside Python. Python 3.14+, not thread-safe.

Syntax

os.reload_environ()

Use it when the process environment was changed behind os.environ's back — via os.putenv, a C extension or an embedding application. It is not thread-safe: another thread reading os.environ or calling getenv at that moment may get an empty result. Added in Python 3.14; earlier versions offer no way to resync the environment after startup.

Examples

import os
os.putenv('DEMO_VAR', '42')      # меняет окружение процесса мимо os.environ
print('DEMO_VAR' in os.environ)   # → False
os.reload_environ()               # перечитать окружение процесса
print(os.environ['DEMO_VAR'])     # → 42
print(os.getenv('DEMO_VAR'))      # → 42
print(os.reload_environ() is None)   # → True (функция ничего не возвращает)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy