On Wed, 13 Mar 2019 at 16:07, Chris Withers <ch...@withers.org> wrote: > > >> Unless I'm missing something, Deferred.addTimeout is really unhelpful in > >> terms on providing context about *what* timed out. > >> TimeoutError(<some number>, 'Deferred') just isn't that useful. > >> > >> How come addTimeout doesn't let you specify a textual reason, or > >> otherwise provide some context about the timeout? > >> > >> Am I missing something obvious here? > > > > I don't know what kind of context do you need :) > > foo.addTimeout(myTimeout, reactor, message='never heard back') > > > You can add your own errback and add your extra error handling there. > > What's the must succinct way to get the above by adding an errback? >
That is subjective :) You can try something like this. def eb_timeoutLog(failure, message): failure.trap(TimeoutError) print(message) deferred = someJob() deferred.addTimeout(10, reactor) deferred.addErrback(eb_timeoutLog, message='never heard back') or like this def eb_timeoutLog(failure, message): failure.trap(TimeoutError) print(message) def add_timeout(deferred, timeout, message): deferred.addTimeout(10, reactor) deferred.addErrback(eb_timeoutLog, message) deferred = someJob() add_timeout(deferred, message='never heard back') > > There is also onTimeoutCancel argument. > > Pretty clunky to write a whole function for either this or the errback > just to change the useless 'Deferred' string in the current > implementation with something useful. For production code I add errbacks anyway. The errback catches various error conditions and does more than just printing a text. I am not missing anything here :) > > If there is anything missing from the API, feel free to send a pull > > request in GitHub. > > What's the likely turn around time from me submitting a PR to when it > ends up in a released version of Twisted that I can use? I don't you the answer to that question. If this is something that you want to be improved, my suggestion is to give it a try. The whole Twisted was created by people who had an issue and were willing to effort required to share the solution with the rest of the world :) > Chris -- Adi Roiban _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python