I found the evil code line like this.
I alter sys.globals['sys'] in sitecustomize.py:
# sitecustomize.py
import sys
class AttributeIsReadonly(ValueError):
pass
class MakeModuleAttributesReadonly(object):
def __init__(self, module, readonly_attributes):
self.module=module
self.readonly_attributes=readonly_attributes
def __setattr__(self, item, value):
if item in ['module', 'readonly_attributes']:
return super(MakeModuleAttributesReadonly, self).__setattr__(item, value)
if item in self.readonly_attributes:
raise AttributeIsReadonly('Access on attribute %r is readonly' % item)
return setattr(self.module, item, value)
def __getattr__(self, item):
return getattr(self.module, item)
sys.modules['sys']=MakeModuleAttributesReadonly(sys, ['path'])
#import sys
#sys.path=sys.path # this will raise the above AttributeIsReadonly
It raises AttributeIsReadonly
and I see the code line and the stack trace.