Re:Guido van Rossum Deconstructing Twisted's Deferreds
by lvh on Tuesday August 20, 2013 @02:05AM
(#6242073)
They get used quite often in production code quite often too: any time you have a synchronous implementation to an asynchronous interface. E.g. your DNS name resoltion thing may have to go query a Postgres database far away (that'd be asynchronous), but maybe it has to grab an entry from a (Python) list (that'd be synchronous).
However, even with respect to your example, it is not idiomatic. Yes you can do anything on anything in Python. And in testing you often monkey-patch and mock things. Which doesn't mean you'd do often in production code. The idea of deferreds is to help with highly concurrent IO applications. It will be a file descriptor (socket) or a timer that will fire your callback more than often.