Skip to content
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

Asyncio Support For ZeroMQ-Based Kernels #21

Closed
peteut opened this issue May 30, 2015 · 4 comments
Closed

Asyncio Support For ZeroMQ-Based Kernels #21

peteut opened this issue May 30, 2015 · 4 comments
Milestone

Comments

@peteut
Copy link

peteut commented May 30, 2015

Is there a chance to get native support for asyncio support for zeroMQ-based kernels?

I came up with this, which works already quite nice (needed a quick solution).

import asyncio
import itertools
from IPython.kernel.zmq.eventloops import register_integration


# FIXME: needs cleanup!
# https://github.com/ipython/ipykernel/blob/197a4a81c38dfcafb1cddb3029329137c8748b23/ipykernel/eventloops.py


@register_integration('asyncio')
def loop_asyncio(kernel):
    '''Start a kernel with asyncio event loop support.'''
    loop = asyncio.get_event_loop()

    def kernel_handler():
        loop.call_soon(kernel.do_one_iteration)
        loop.call_later(kernel._poll_interval, kernel_handler)

    loop.call_soon(kernel_handler)
    try:
        if not loop.is_running():
            loop.run_forever()
    finally:
        loop.close()

Invoking this cell prior the %gui asyncio cell already did the job.

@takluyver
Copy link
Member

I made a very experimental asyncio kernel, but I wouldn't recommend that anyone use it seriously.

What are you trying to do with asyncio integration?

@peteut
Copy link
Author

peteut commented Jun 2, 2015

Thanks for the link, I'll give it a try!

My scenario is this:
I have a Notebook with some interactive widgets and some asyncio.coroutine.
The master coroutine checks some widget state and joins the workers/tasks upon request.

@jasongrout
Copy link
Member

We've now merged this in #246. Thanks again!

@jasongrout
Copy link
Member

Note that I also wrote a short notebook illustrating some ways the widgets can be used asynchronously at https://github.com/jupyter-widgets/ipywidgets/blob/master/docs/source/examples/Widget%20Asynchronous.ipynb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants