'copied from standard repr.py and fixed to work on multithreadedly mutating dicts.'

def repr_dict(self, obj, level):

    if (level <= 0):
        return '{...}'
    s = ''
    n = len(obj)
    items = obj.items()[:min(n, self.maxdict)]
    items.sort()
    for (key, val) in items:
        entry = ((self.repr1(key, (level - 1)) + ':') + self.repr1(val, (level - 1)))
        if s:
            s = (s + ',    ')
        s = (s + entry)
    if (n > self.maxdict):
        s = (s + ',    ...')
    return (('{' + s) + '}')
