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

Oon-Ee Ng ngoonee.talk at gmail.com
Tue Oct 4 00:19:55 MDT 2016


On Tue, Oct 4, 2016 at 12:42 PM, meejah <meejah at meejah.ca> wrote:
> 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()"

Why yes, that makes sense.
>
>> 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()
>
I would if I could, most of my projects are already there but last I
checked (beginning of the year) the _threadedselect reactor wasn't
fully ready yet, and AMP wasn't ported. I see a lot of progress on
that front with Amber's frequent updates here, so will migrate when I
can, but in the meantime I'm keeping things on python2 (no official
release of the app yet, so its not a big deal to shift when ready).




More information about the Twisted-Python mailing list