[Python-ideas] Async API

Laurens Van Houtven _ at lvh.cc
Sat Oct 27 17:11:33 CEST 2012


On Fri, Oct 26, 2012 at 7:49 PM, Yury Selivanov <yselivanov.ml at gmail.com>wrote:

> If it is decorated, though, how can I invoke it with a timeout?
>

The important thing to remember is that the fundamental abstraction at play
here is the deferred. Calling such a decorated function gives you a
deferred. So, you call it with a timeout the same way you timeout (cancel)
any deferred:

d = deferred_returning_expression
reactor.callLater(timeout, d.cancel)

Where deferred_returning_expression can be anything, including calling your
@inlineCallbacks-decorated function.

The way it fits in with all existing stuff, making it look an awful lot
like a lot of existing stuff, is probably why deferred cancellation is one
of the more recent features to make it into twisted: a lot of people did
similar things using the tools that were already there.



> -
> Yury
>
-- 
cheers
lvh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121027/d21e4386/attachment.html>


More information about the Python-ideas mailing list