[Twisted-Python] inlineCallbacks as a blocking approximator (stylistic)

meejah meejah at meejah.ca
Mon Oct 3 22:42:45 MDT 2016


Oon-Ee Ng <ngoonee.talk at gmail.com> writes:

> The closest I'm able to come to that so far is for my function to be
> decorated with @defer.inlineCallbacks which will then look like this
>
>     val = yield doSomeCallRemoteCallHere(args)
>     myWidget.text = val

You can even do "myWidget.text = yield somethingDeferred()"

> Is this as 'good' (for the subjective readability concern) as it gets?

Yes.
Unless you move everything to Python 3 and then you can use the async /
await syntax (with Twisted), which is more-or-less the same as the above
(but you avoid the decorator). It would look like:

    myWidget.text = await somethingDeferred()

-- 
meejah




More information about the Twisted-Python mailing list