[IPython-User] [Min/Brian help] Re: Empty tb field in taskresult.failure

Fernando Perez fperez.net@gmail....
Tue Jul 20 13:49:27 CDT 2010

Hi Chris,

On Tue, Jul 20, 2010 at 11:36 AM, Chris Filo Gorgolewski
<chris.gorgolewski@gmail.com> wrote:
> thanks. I'll check it out and test soon. One quick question, however,
> will I get a proper traceback if I do failure.raise_exception()?

No, not really: raise_exception() happens locally (client-side)
whereas the real stack was in your engine, possibly a while ago, and
in general long gone. So if you raise_exception() you see this:

In [9]: run task_bug.py
TaskResult[ID:2]:<twisted.python.failure.Failure <type 'exceptions.IOError'>>
Failure traceback: None

In [10]: res.raise_exception()
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
  File "/home/fperez/usr/opt/virtualenv/ipython-0.10.1/lib/python2.6/site-packages/IPython/kernel/task.py",
line 514, in raise_exception
  File "/usr/lib/python2.6/dist-packages/twisted/python/failure.py",
line 326, in raiseException
    raise self.type, self.value, self.tb
IOError: failure test

The right message, the wrong stack.  This isn't easily fixable in the
short term (though an important point we do keep in mind for long-term

The solution is to use the traceback print methods of the failure when
debugging, like Brief or normal:

In [11]: res.failure.printBriefTraceback()
Traceback: <type 'exceptions.IOError'>: failure test
--- <exception caught here> ---

In [12]: res.failure.printTraceback()
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.6/foolscap/referenceable.py", line
60, in doRemoteCall
    res = meth(*args, **kwargs)
  File "/home/fperez/usr/opt/virtualenv/ipython-0.10.1/lib/python2.6/site-packages/IPython/kernel/enginefc.py",
line 113, in remote_execute
    d = self.service.execute(lines)
  File "/home/fperez/usr/opt/virtualenv/ipython-0.10.1/lib/python2.6/site-packages/IPython/kernel/engineservice.py",
line 406, in execute
    d = self.executeAndRaise(msg, self.shell.execute, lines)
  File "/home/fperez/usr/opt/virtualenv/ipython-0.10.1/lib/python2.6/site-packages/IPython/kernel/engineservice.py",
line 392, in executeAndRaise
    f = failure.Failure(ev,et,tb)
--- <exception caught here> ---
  File "/home/fperez/usr/opt/virtualenv/ipython-0.10.1/lib/python2.6/site-packages/IPython/kernel/engineservice.py",
line 381, in executeAndRaise
    result = callable(*args, **kwargs)
  File "/home/fperez/usr/opt/virtualenv/ipython-0.10.1/lib/python2.6/site-packages/IPython/kernel/core/interpreter.py",
line 375, in execute_block
    exec code in self.user_ns
  File "<string>", line 1, in <module>

  File "<string>", line 2, in fail

  File "<string>", line 2, in crash

  File "<string>", line 2, in boom

exceptions.IOError: failure test

In this case, the script I ran was:

In [13]: !cat task_bug.py
# http://gist.github.com/475391

from IPython.kernel import client

taskclient = client.TaskClient()

cmd = """
def boom():
    raise IOError('failure test')

def crash():

def fail():

result = fail()
task = client.StringTask(cmd, pull = 'result')
res = taskclient.run(task, block = True)

print res
if res.failure:
    print 'Failure traceback:', res.failure.tb

Let us know if that works better in practice, with your real-world code.



More information about the IPython-User mailing list