Created
January 11, 2024 13:45
-
-
Save miraculixx/2b7e3e72ec5cca072b3d650c492f31c2 to your computer and use it in GitHub Desktop.
trace manipulations to os.environ in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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