New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port greenio to Trollius #5
Conversation
To test greenio on Trollius, you need to use the branch trollius_greenio which as a tasks.task_factory variable. I just sent an email to ask to add a new BaseEventLoop.task_factory attribute to python-tulip mailing list. |
@greenio.task | ||
def test(): | ||
return (yield from foo()) | ||
if trollius is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the need to do this, but it still feels very wrong :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, can you elaborate? What's "wrong"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the need: "yield from" syntax raises a SyntaxError on Python 2, you just cannot import the module.
It may be possible to use different files, but I prefer to keep all code in a single code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that, that's the part that feels wrong, big #ifdef trollius
around blocks of code.
But I guess this is how it goes....
@Haypo I see the reason. How about a rather obscure, but still working solution: before trying to import |
My asyncio patch adding task_factory is under review. I started with asyncio.tasks.task_factory, which is the option chosen in this pull request. I then moved the factory to BaseEventLoop. But Guido van Rossum proposed to move the factory to the event loop policy. If the task factory is in the event loop policy, we can offer two event loop policies:
So it puts less pressure on the import part :-) I didn't check which parts should be specific to trollius or asyncio. There is a least the GreenTask class which should inherit from asyncio.Task or from trollius.Task. I will update this pull request when the API for task_factory will be decided. FYI the review: |
The task factory has been implemented in Tulip: it's a new nice BaseEventLoop.create_task() method, instead of an ugly global task_factory variable. I merged Tulip into Trollius and updated the pull request. |
@Haypo Thanks Victor. I'll review your PR in detail shortly. |
@1st1 : Oh, I forgot to fix the "import order" issue: provide 2 event loop policies (asyncio & trollius), not only one. |
Ok, I think that the code is now ready for a review. Let me explain the whole change:
|
I reviewed my code on Github and I found some issues. They should be fixed now. |
I moved Python2-specific changes in a new pull request to make this pull request simpler: #7 |
All other PRs are merged. Please update this one. |
- add GreenTrolliusEventLoopPolicy for Trollius which creates tasks compatible with Trollius - yield_from() now also accepts coroutine objects, so the caller doesn't have to create a task object (which may not be compatible with asyncio *and* trollius)
- with asyncio, greenio.task(coro) now creates GreenTask, not Task - move the "if trollius is not None:" out of the function, add _create_task() function
I abandon this pull request in favor of my updated pull request #9. |
Hi,
I would like to use greenio in OpenStack to be able to use the asyncio API be execute tasks in greenlet. OpenStack projects are heavily based on eventlet and it's not possible to switch from eventlet to asyncio in one step, it should be done incrementally.
asyncio and Python 3 cannot be requirements on OpenStack because OpenStack is already deployed in production with Python 2, and projects don't support Python 3 yet (most clients are Python 3 compatibility, but not servers yet).
My plan is to use Trollius with greenio, replace incrementally eventlet with Trollius in OpenStack:
http://haypo-notes.readthedocs.org/openstack.html#roadmap
Victor