[Twisted-Python] twisted eats the error

L. Daniel Burr ldanielburr at me.com
Mon Feb 13 11:35:07 MST 2017


Hi Steven,

On February 13, 2017 at 12:01:49 PM, steven meiers (commercials24 at yahoo.de) wrote:


> Sorry, your code example and your explanation don’t make clear what
> you expect to happen, and when.  When you say “the first method that
> is called from my code”, are you referring to  aSillyBlockingMethod,
> or runEverySecond?  In the deferToThread case, you are calling the
> former; in the task.LoopingCall case, you are calling the latter.

Ah youre right, i forgot to write about the most important part.
if the datetime line is wrong you get  
Unhandled Error  

i was looking for a way to get the original error message that:
print(datetime.now().strftime('%H:%M:%S'))

throws if used outside of twisted code.

i know how to correct the code but i would like to know why i dont get
that error on the console.


[SNIP]

The “Unhanded error in Deferred” isn’t coming from your call to deferToThread, it is coming from your task.LoopingCall.  When you invoke .start() on your LoopingCall instance, it returns a Deferred, which fires its assigned callback handler when you call .stop() on the LoopingCall instance, and which fires its assigned errback handler if an exception occurs while running the function (in this case runEverySecond) passed to the LoopingCall.

In other words, you need this:

l = task.LoopingCall(runEverySecond, ‘lala’)
l.addErrback(printError)

Hope this helps,

L. Daniel Burr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20170213/6ff6bddf/attachment-0002.html>


More information about the Twisted-Python mailing list