Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Created January 11, 2024 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miraculixx/2b7e3e72ec5cca072b3d650c492f31c2 to your computer and use it in GitHub Desktop.
Save miraculixx/2b7e3e72ec5cca072b3d650c492f31c2 to your computer and use it in GitHub Desktop.
trace manipulations to os.environ in python
# to investigate which code is manipulating os.environ
class trace(dict):
def __delitem__(self, k):
self._trace(k)
super().__delitem__(k)
def _trace(self, k):
import inspect
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
caller = calframe[2][3]
caller = getattr(caller, '__name__', caller)
print(f'{caller} deleted {k}')
def pop(self, k=None, d=None):
self._trace(k)
return super().pop(k, d)
import os
os.environ = trace(os.environ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment