beeware / bugjar

A interactive graphical debugger for Python code.
BSD 3-Clause "New" or "Revised" License
249 stars 31 forks source link

Circular Reference when debugging #5

Closed khoobks closed 11 years ago

khoobks commented 11 years ago

The bugjar debugger will throw a circular reference exception if you debug the files below.

Exception

Traceback (most recent call last):
  File "D:\BackupSync\Code\django-bugjar\VirtualEnv\lib\site-packages\bugjar\net.py", line 575, in run
    debugger._runscript(filename)
  File "D:\BackupSync\Code\django-bugjar\VirtualEnv\lib\site-packages\bugjar\net.py", line 552, in _runscript
    self.run('execfile(%r)' % filename)
  File "C:\Python27\Lib\bdb.py", line 387, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "d:\backupsync\code\django-bugjar\testproject\test.py", line 8, in <module>
    main()
  File "d:\backupsync\code\django-bugjar\testproject\test.py", line 3, in main
    other = __import__('other')
  File "d:\backupsync\code\django-bugjar\testproject\other.py", line 2, in <module>
    class Cow(object):
  File "d:\backupsync\code\django-bugjar\testproject\other.py", line 6, in Cow
    def talk(self):
  File "C:\Python27\Lib\bdb.py", line 52, in trace_dispatch
    return self.dispatch_return(frame, arg)
  File "C:\Python27\Lib\bdb.py", line 85, in dispatch_return
    self.user_return(frame, arg)
  File "D:\BackupSync\Code\django-bugjar\VirtualEnv\lib\site-packages\bugjar\net.py", line 205, in user_return
    self.output('return', retval=return_value)
  File "D:\BackupSync\Code\django-bugjar\VirtualEnv\lib\site-packages\bugjar\net.py", line 124, in output
    self.client.sendall(json.dumps((event, data)) + Debugger.ETX)
  File "C:\Python27\Lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Python27\Lib\json\encoder.py", line 201, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Python27\Lib\json\encoder.py", line 264, in iterencode
    return _iterencode(o, 0)
ValueError: Circular reference detected

There are two test files test.py and other.py

test.py

def main():
    while True:
        other = __import__('other')
        #cow = other.Cow()
        #cow.talk()

if __name__ == '__main__':
    main()

other.py

class Cow(object):
    def __init__(self):
        pass

    def talk(self):
        print 'Moo'

To produce the exception start the debugger and keep clicking "step".

freakboy3742 commented 11 years ago

Note that db3b2c3 is probably a temporary workaround. The problem arises because the return value was trying to JSON encode the return stack frame, which is self referential; however, we're currently only displaying the stack frame one level deep, so we don't need the rich JSON content. Looking forward, we'll probably want to address that to give better insights on the stack frame viewer.