On Mon, 23 Dec 2013 22:25:59 +0100
Tobias Oberstein
<[email protected]> wrote:
> Am 23.12.2013 22:07, schrieb Guido van Rossum:
> > Protocol callbacks don't have a return value and can't (or shouldn't)
> > block. You can use async() or Task() to spawn a coroutine. You might
> 
> Thanks for making this clear. Just from looking at the signature of 
> data_received vs Twisted dataReceived, I first (naively) assumed similar 
> behavior. It's clear now, and in fact I got it working in the meantime 
> (using a deque() and a Future to signal).

I'm curious: what is the difference in behaviour between Twisted's
dataReceived and asyncio's data_received?

> I have now another issue. I am _extending_ support of a WebSocket 
> framework (https://github.com/tavendo/AutobahnPython) from Twisted/Py2 
> to Py3 and asyncio. I am _nearly_ there. 90% code is shared between 
> Twisted and asyncio. But, in the shared code, I have multiple places:
> 
>        if PY3 and self._coroutines:
>           yield from self.consumeData()
>        else:
>           self.consumeData()

I don't really understand. If consumeData() isn't supposed to wait on
I/O, you don't need to "yield from" it.

> I guess that works on Py3/Twisted (if Twisted would support Py3 some 
> time), but it breaks Py2 .. "yield from" is a syntax error, even if PY3 
> is False. There is no #ifndef in Python.

If you want to write code that's compatible with Python 2, you
shouldn't use "yield from" at all. Just write callback-style code,
rather than coroutine-style.

If you're a bit stuck, you can take a look at Obelus:
https://pypi.python.org/pypi/obelus/

Regards

Antoine.


Reply via email to