> Anytime you did a blocking operation you'd have to use Twisted's
> callback style, which is a chain of functions where a normal program
> would have a single function. (Thus you have to pass what would
> normally be local variables as arguments, or put the chunks together
> in a class and use instance attributes for your "local variables".)
Well, with inlineCallbacks it does not look so bad
<hint>
@defer.inlineCallbacks
def someFunction():
a = 1
b = yield deferredReturningFunction(a)
c = yield anotherDeferredReturningFunction(a, b)
defer.returnValue(c)
</hint>
Internally such function maps to asynchronous callback on every yield,
but readability does not suffer (the only difference comparing to
synchronous function is presence of yield's and the decorator). The
only true problem is that this syntax requires python 2.5. For python
2.4 there is defer.deferredGenerator which requires a bit more elaborate
syntax:
d = defer.waitForDeferred(deferredReturningFunction(a))
b = d.getValue()
Would be interesting if somebody tried to provide WSGI server which
in addition to standard api, would handle deferred as a result.
Although a lot of things would need to be adapted...
--
----------------------------------------------------------------------
| Marcin Kasperski | Software is not released,
| http://mekk.waw.pl | it is allowed to escape.
| |
----------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---