Skip to content

Commit

Permalink
Saving and restoring environment variables that tend to get clobbered…
Browse files Browse the repository at this point in the history
… by XMSession.
  • Loading branch information
ballenspectric committed Aug 23, 2024
1 parent 06d9981 commit 860fe2e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xmextras/xm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def XMSessionContext():
answer = session.xmpy.res['answer']
'''
# Save environment variables that tend
# to get clobbered by XMSession.
saved_env_vars = {k: v for k, v in os.environ.items() if k.startswith('XM')}

session = XMSession()
session.start()

Expand All @@ -42,6 +46,11 @@ def XMSessionContext():
finally:
session.end()

# Restore environment variables to their
# state from before the XMSession.
for k, v in saved_env_vars.items():
os.environ[k] = v

def info(session):
'''
Returns basic info about an X-Midas instance, which can be useful
Expand Down

0 comments on commit 860fe2e

Please sign in to comment.