use safeRepr to catch crashes in __repr__ and __str__ calls

This commit is contained in:
Darren Ranalli 2007-04-10 22:24:38 +00:00
parent 0c34c9d377
commit a0d32f9e29

View File

@ -47,7 +47,7 @@ class Indirection:
self._refCount = 0 self._refCount = 0
if dictKey is not NoDictKey: if dictKey is not NoDictKey:
# if we can repr/eval the key, store it as an evalStr # if we can repr/eval the key, store it as an evalStr
keyRepr = repr(dictKey) keyRepr = safeRepr(dictKey)
useEval = False useEval = False
try: try:
keyEval = eval(keyRepr) keyEval = eval(keyRepr)
@ -67,7 +67,7 @@ class Indirection:
self.dictKey = weakref.ref(dictKey) self.dictKey = weakref.ref(dictKey)
self._isWeakRef = True self._isWeakRef = True
except TypeError, e: except TypeError, e:
ContainerLeakDetector.notify.debug('could not weakref dict key %s' % dictKey) ContainerLeakDetector.notify.debug('could not weakref dict key %s' % keyRepr)
self.dictKey = dictKey self.dictKey = dictKey
self._isWeakRef = False self._isWeakRef = False
@ -337,7 +337,6 @@ class FindContainers(Job):
# that container is gone, try again # that container is gone, try again
self._curObjRef = None self._curObjRef = None
continue continue
#print '%s: %s, %s' % (id(curObj), type(curObj), self._id2ref[id(curObj)])
self.notify.debug('--> %s' % self._curObjRef) self.notify.debug('--> %s' % self._curObjRef)
# keep a copy of this obj's eval str, it might not be in _id2ref # keep a copy of this obj's eval str, it might not be in _id2ref
@ -373,7 +372,7 @@ class FindContainers(Job):
attr = curObj[key] attr = curObj[key]
except KeyError, e: except KeyError, e:
# this is OK because we are yielding during the iteration # this is OK because we are yielding during the iteration
self.notify.debug('could not index into %s with key %s' % (curObjRef, key)) self.notify.debug('could not index into %s with key %s' % (curObjRef, safeRepr(key)))
continue continue
isContainer = self._isContainer(attr) isContainer = self._isContainer(attr)
notDeadEnd = False notDeadEnd = False
@ -593,7 +592,7 @@ class CheckContainers(Job):
(name, itype(container), idx2id2len[self._index][id], (name, itype(container), idx2id2len[self._index][id],
fastRepr(container, maxLen=CheckContainers.ReprItems))) fastRepr(container, maxLen=CheckContainers.ReprItems)))
self.notify.warning(msg) self.notify.warning(msg)
self.notify.warning('sending notification...') self.notify.info('sending notification...')
yield None yield None
for result in self._leakDetector.getContainerByIdGen(id): for result in self._leakDetector.getContainerByIdGen(id):
yield None yield None