[Twisted-Python] The case of the missing Traceback

Dan tw.1 at pyxos.com
Tue Nov 3 13:52:45 EST 2009


I was playing around with Twisted today and ran into a problem where 
Tracebacks aren't emitted on stderr after a deferred callback from a 
process called launched by reactor.spawnProcess.  The simplified test 
case is below.  I put "x = y" in the  callback function to generate 
an exception, y doesn't exist.  Uncomment "x = z" right before the 
callback and it produces the traceback on stderr just fine.

System is Linux, Python 2.6 and Twisted 8.2.



from twisted.internet import reactor, protocol, defer
import sys


def err(s):
     sys.stderr.write(s+'\n')
     sys.stderr.flush()


def test():
     err('test')
     cat = MyPP()
     reactor.spawnProcess(cat, "/bin/cat", ["cat", "-"], {})
     d = cat.send("Hello world")
     d.addCallback(response)


def response(resp):
     err('response called')
     x = y
     err(resp)


class MyPP(protocol.ProcessProtocol):
     def __init__(self):
         self.defer = defer.Deferred()

     def outReceived(self, data):
         err("outReceived! with %d bytes" % len(data))
         err("    %s" % data)
         self.defer.callback(data)

     def send(self, c):
         self.transport.write("%s\n" % c)
         #x = z
         return self.defer


if(__name__=='__main__'):
     reactor.callWhenRunning(test)
     reactor.run()






More information about the Twisted-Python mailing list