MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / change_env

Function change_env

tensorpack/utils/utils.py:69–97  ·  view source on GitHub ↗

Args: name(str): name of the env var val(str or None): the value, or set to None to clear the env var. Returns: a context where the environment variable ``name`` being set to ``val``. It will be set back after the context exits.

(name, val)

Source from the content-addressed store, hash-verified

67
68@contextmanager
69def change_env(name, val):
70 """
71 Args:
72 name(str): name of the env var
73 val(str or None): the value, or set to None to clear the env var.
74
75 Returns:
76 a context where the environment variable ``name`` being set to
77 ``val``. It will be set back after the context exits.
78 """
79 oldval = os.environ.get(name, None)
80
81 if val is None:
82 try:
83 del os.environ[name]
84 except KeyError:
85 pass
86 else:
87 os.environ[name] = val
88
89 yield
90
91 if oldval is None:
92 try:
93 del os.environ[name]
94 except KeyError:
95 pass
96 else:
97 os.environ[name] = oldval
98
99
100_RNG_SEED = None

Callers 3

load_caffeFunction · 0.85
_use_ldconfigFunction · 0.85
change_gpuFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected