getProcessOutput() overly complicates error handling in 8.2.0
| Newsgroups | gmane.comp.python.twisted.bugs |
|---|---|
| Message-ID | <[email protected]> |
New submission from ruttbe <None>:
For background, you can read http://twistedmatrix.com/pipermail/twisted-python/2009-June/019872.html which contains the thread of discussion and the workaround supplied by glyph.
With twisted 8.2.0, I observe that programs that generate logging output on stderr and also exit nonzero now require 2 errbacks to be added - one for the deferred returned by getProcessOutput which fires an errback because it saw some stderr, and one caught within that errback for the process ending (without adding the second errback you get the dreaded "Unhandled error in Deferred" upon exiting the program). Observe the complexity of the errback below:
{{{
def foo():
d = getProcessOutput('/some/non/existent/program')
def cb(result):
print 'cb: %s' % (result)
def eb(failure):
failure.trap(IOError)
def endedException(ended):
print 'really, caught it!'
failure.value.processEnded.addErrback(endedException)
print 'eb caught the failure!'
d.addCallback(cb)
d.addErrback(eb)
}}}
compared with a simpler approach in 2.1.0:
{{{
def foo():
d = getProcessOutput('/some/non/existent/program')
def cb(result):
print 'cb: %s' % (result)
def eb(failure):
print 'eb caught the failure! %s' % (failure)
d.addCallback(cb)
d.addErrback(eb)
}}}
Because the behavior changes on the default use of getProcessOutput() (errortoo=0 by default), and error handling is made quite a bit more complicated, may we consider this a bug?
----------
Type : defect
Component: core
Keywords :
Priority : normal
Nosy :
----------
http://twistedmatrix.com/trac/ticket/3892