The other day I was experimenting with the inlineCallbacks decorator in Twisted 
15.4, and occasionally when I'd typo a variable name or similar, I'd  get an 
"unhandled error" in the log without a traceback, which was rather unhelpful. 
Eventually, I managed to produce the following test-case:

    https://gist.github.com/OptiverTimAll/43263a7a4cf5a298e8f5

If I run it as-is, I get the following unhelpful output:

    CRITICAL:twisted:Unhandled error in Deferred:
    CRITICAL:twisted:

If I comment out the line that redirects Twisted's logging to the standard 
library's logging system, I get much more helpful output:

    Unhandled error in Deferred:


    Traceback (most recent call last):
      File "./ic-test.py", line 20, in <module>
        bogus_callback()
      File 
"/home/timall/.virtualenvs/txfuse/lib/python2.7/site-packages/twisted/internet/defer.py",
 line 1274, in unwindGenerator
        return _inlineCallbacks(None, gen, Deferred())
    --- <exception caught here> ---
      File 
"/home/timall/.virtualenvs/txfuse/lib/python2.7/site-packages/twisted/internet/defer.py",
 line 1128, in _inlineCallbacks
        result = g.send(result)
      File "./ic-test.py", line 17, in bogus_callback
        yield does_not_exist()
    exceptions.NameError: global name 'does_not_exist' is not defined

I expected that changing the destination of log messages wouldn't change their 
content, but apparently I was wrong. I got the incantation for re-routing 
Twisted's logging system into the Python one by stitching together 
code-snippets from 
http://twistedmatrix.com/documents/current/core/howto/logger.html#starting-the-global-log-publisher
 Is there some better way, or some other thing I should be doing?

--
Timothy Allen
Tools Developer

39 Hunter Street, Sydney NSW 2000
T: +61 2 9275 6000 │ F: +61 2 9275 6150
W: http://www.optiver.com/sydney
We're hiring (lots)!

Information contained in this communication (including any attachments) is 
confidential and may be privileged or subject to copyright.  If you have 
received this communication in error you are not authorised to use the 
information in any way and Optiver requests that you notify the sender by 
return email, destroy all copies and delete the information from your system.  
Optiver does not represent, warrant or guarantee that this communication is 
free from computer viruses or other defects or that the integrity of this 
communication has been maintained.  Any views expressed in this communication 
are those of the individual sender.  Optiver does not accept liability for any 
loss or damage caused directly or indirectly by this communication or its use.

Please consider the environment before printing this email.

_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to