On 20 February 2014 11:33, Victor Stinner <[email protected]> wrote:

> Hi,
>
> Tulip uses "yield from" whereas this instruction is new in Python 3.3
> and cannot be used on Python 2, so Trollius uses "yield" instead. The
> problem is that third-party projects like aiohttp uses "yield from".
>
> On the OpenStack mailing list, the following question was asked:
> "How useful is trollius if we can't use other thirdparty libraries
> written for asyncio?"
>
>
In pulsar 0.8 (not released yet! requires asyncio/trollius) I use a
specialised asyncio Task class which is tolerant to yielded generators.
The client can do both yield or yield from and it works fine (yield ~30%
slower on some basic benchmarks)
Look for the Task class and async function in here for details
https://github.com/quantmind/pulsar/blob/yieldfrom/pulsar/async/futures.py


> Would it be possible to support CPython 3.4 / Tulip (Python 3.3) /
> Trollius (Python 2.6/2.7, but works also on Python 3) in the same code
> base without duplicating almost all the code?
>

maybe setting a task_factory in the event loop?
Pulsar creates tasks from the eventloop task_factory callable if it exists,
otherwise reverts to the standard asyncio Task.
In this way switching task class can be done via the current asyncio api by
setting a new event loop policy.


> Trollius is currently a branch of Tulip. It's not easy to maintain it
> (but I do maintain it, it's possible ;-)). I'm not sure that each
> third-party project would like its own Trollius branch.
>
>
I thought about that but sensationally I came to the right decision, no.
Asyncio does exactly what I needed and thanks to trollius I was able to
remove the whole async internals in pulsar and concentrate on the apps.
Your effort is very much appreciated.



> I don't know if it would be possible to replace "yield from" with
> "yield" at runtime, for example when a module is imported. The Python
> 2 parser cannot be used for that, because "yield from" raises a syntax
> error.
>
> It may be possible to write a script replacing "yield from " with
> "yield " directly in the source code, something like 2to3, but I don't
> like this option.
>

ditto

Reply via email to