Skip to content

Instantly share code, notes, and snippets.

@josh-howes
Last active November 13, 2018 21:20
Show Gist options
  • Select an option

  • Save josh-howes/50e53f3ad52e11b2bc85fb6964147107 to your computer and use it in GitHub Desktop.

Select an option

Save josh-howes/50e53f3ad52e11b2bc85fb6964147107 to your computer and use it in GitHub Desktop.

Revisions

  1. josh-howes revised this gist Sep 10, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions noblock.py
    Original file line number Diff line number Diff line change
    @@ -17,3 +17,7 @@ def noblock(line, cell):
    executor = None # use default
    future = async_loop.run_in_executor(executor, partial(ipy.run_cell, raw_cell=cell))
    future.add_done_callback(alert_done)

    def alert_done():
    """ Code to execute when the cell finishes running! """
    pass
  2. josh-howes revised this gist Sep 10, 2018. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions noblock.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    """
    https://jupyter.readthedocs.io/en/latest/architecture/how_jupyter_ipython_work.html
    http://www.tornadoweb.org/en/stable/
    https://jupyter-notebook.readthedocs.io/en/stable/extending/handlers.html
    """
    from IPython import get_ipython
    from IPython.core.magic import register_cell_magic
    from tornado import ioloop
  3. josh-howes created this gist Sep 10, 2018.
    14 changes: 14 additions & 0 deletions noblock.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    from IPython import get_ipython
    from IPython.core.magic import register_cell_magic
    from tornado import ioloop
    from functools import partial


    @register_cell_magic
    def noblock(line, cell):
    """ Jupyter Magic to run cell code asynchronously """
    async_loop = ioloop.IOLoop.instance()
    ipy = get_ipython()
    executor = None # use default
    future = async_loop.run_in_executor(executor, partial(ipy.run_cell, raw_cell=cell))
    future.add_done_callback(alert_done)