%%async_run
: an IPython notebook magic for asynchronous cell executionThe IPython notebook
project is one the preferred tools of data scientists,
and it is nowadays the bastion for Reproducible Research.
In fact, notebooks are now used as in-browser IDE (Integrated Development Environment) to implement the whole data analysis process, along with the corresponding documentation.
However, since this kind of processes usually include heavy-weight computations, it may likely happen that execution results get lost if something wrong happens, e.g. the connection to the notebook server hangs or an accidental page refresh is issued.
To this end, [%]%async_run
notebook line/cell magic to the rescue.
In this talk, I would like to talk about some of the technologies I played with since I decided to develop
this extension.
These technologies include asynchronous I/O libraries (e.g. asyncio
, tornado.websocket
),
multiprocessing
, along with IPython kernels
and notebooks
.
During the talk, I would like to discuss pitfalls, failures, and adopted solutions (e.g. namespace management among processes) , aiming at getting as many feedbacks as possible from the community.
A general introduction to the actual state-of-the-art of the Jupyter projects (an libraries) will be presented as well, in order to help those who are willing to know some more details about the internals of IPython.
Slides of the talk are available on my SpeakerDeck profile.
Enabling the magic is simple as copying files into a directory. Open the terminal and:
cp -R async_run_ipython_magic.py run_async/ ~/.ipython/profile_default/startup/
After that, the magic will be enabled by default at the startup of each Jupyter/IPython sessions.
The only two main requirements for this Magic are notebook
and tornado
(which will be
indeed installed by the jupyter notebook itself). Moreover, the psutil
module is needed.
To ease the installation of all the requirements, a requirements.txt
file is provided in the repo
for pip installing:
pip install -f requirements.txt
So far, this magic works only with Python 3.
For example, it relies on the concurrent.futures
module to allow for the multiprocessing execution.
This module is only available in Python 3 standard library. For Python 2, you have to pip install
the futures
A couple of fix could be included in the code to easily support Python 2 as well, leveraging on the six
module. These fixes will be soon included in the code base.
Three [%]%async_*
magics are provided within this package:
%async_run_server
: Spawns the AsyncRunServer
process, which is in charge of handling the async cell execution inside a Tornado WebApplication
and IOLoop
.
%async_stop_server
: Stops the AsyncRunServer
running process, if any.
[%]%async_run
: Line/Cell Magic to asynchronously execute the content of the line/cell, respectively.
Please, check out the examples
folder for examples and hints for usage (so far, very few examples available. More to come!)
If you want to run the server in a terminal and get the log output, move to the startup
folder and execute:
python -m run_async.run_server
I stumbled across this and I think this could be a huge step forward for many things in Jupyter. Specifically the framework to allow OTHER magic functions to operate with async io and do things like submit queries to remote servers without blocking. I want to get into understanding things, but it appears some of the ways you call IOloop are deprecated. Any chance you can take a look at things and it working with Tornado 6.2.
From there I want to start learning how things work and I will obviously share back what I do! Thank
Bumps nbconvert from 4.2.0 to 6.5.1.
Sourced from nbconvert's releases.
Release 6.5.1
No release notes provided.
6.5.0
What's Changed
- Drop dependency on testpath. by
@anntzer
in jupyter/nbconvert#1723- Adopt pre-commit by
@blink1073
in jupyter/nbconvert#1744- Add pytest settings and handle warnings by
@blink1073
in jupyter/nbconvert#1745- Apply Autoformatters by
@blink1073
in jupyter/nbconvert#1746- Add git-blame-ignore-revs by
@blink1073
in jupyter/nbconvert#1748- Update flake8 config by
@blink1073
in jupyter/nbconvert#1749- support bleach 5, add packaging and tinycss2 dependencies by
@bollwyvl
in jupyter/nbconvert#1755- [pre-commit.ci] pre-commit autoupdate by
@pre-commit-ci
in jupyter/nbconvert#1752- update cli example by
@leahecole
in jupyter/nbconvert#1753- Clean up pre-commit by
@blink1073
in jupyter/nbconvert#1757- Clean up workflows by
@blink1073
in jupyter/nbconvert#1750New Contributors
@pre-commit-ci
made their first contribution in jupyter/nbconvert#1752Full Changelog: https://github.com/jupyter/nbconvert/compare/6.4.5...6.5
6.4.3
What's Changed
- Add section to
customizing
showing how to use template inheritance by@stefanv
in jupyter/nbconvert#1719- Remove ipython genutils by
@rgs258
in jupyter/nbconvert#1727- Update changelog for 6.4.3 by
@blink1073
in jupyter/nbconvert#1728New Contributors
@stefanv
made their first contribution in jupyter/nbconvert#1719@rgs258
made their first contribution in jupyter/nbconvert#1727Full Changelog: https://github.com/jupyter/nbconvert/compare/6.4.2...6.4.3
6.4.0
What's Changed
- Optionally speed up validation by
@gwincr11
in jupyter/nbconvert#1672- Adding missing div compared to JupyterLab DOM structure by
@SylvainCorlay
in jupyter/nbconvert#1678- Allow passing extra args to code highlighter by
@yuvipanda
in jupyter/nbconvert#1683- Prevent page breaks in outputs when printing by
@SylvainCorlay
in jupyter/nbconvert#1679- Add collapsers to template by
@SylvainCorlay
in jupyter/nbconvert#1689- Fix recent pandoc latex tables by adding calc and array (#1536, #1566) by
@cgevans
in jupyter/nbconvert#1686- Add an invalid notebook error by
@gwincr11
in jupyter/nbconvert#1675- Fix typos in execute.py by
@TylerAnderson22
in jupyter/nbconvert#1692- Modernize latex greek math handling (partially fixes #1673) by
@cgevans
in jupyter/nbconvert#1687- Fix use of deprecated API and update test matrix by
@blink1073
in jupyter/nbconvert#1696- Update nbconvert_library.ipynb by
@letterphile
in jupyter/nbconvert#1695- Changelog for 6.4 by
@blink1073
in jupyter/nbconvert#1697New Contributors
... (truncated)
7471b75
Release 6.5.1c1943e0
Fix pre-commit8685e93
Fix tests0abf290
Run black and prettier418d545
Run test on 6.x branchbef65d7
Convert input to string prior to escape HTML0818628
Check input type before escapingb206470
GHSL-2021-1017, GHSL-2021-1020, GHSL-2021-1021a03cbb8
GHSL-2021-1026, GHSL-2021-102548fe71e
GHSL-2021-1024Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps notebook from 6.1.5 to 6.4.12.
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps ipython from 5.1.0 to 7.16.3.
d43c7c7
release 7.16.35fa1e40
Merge pull request from GHSA-pq7m-3gw7-gq5x8df8971
back to dev9f477b7
release 7.16.2138f266
bring back release helper from master branch5aa3634
Merge pull request #13341 from meeseeksmachine/auto-backport-of-pr-13335-on-7...bcae8e0
Backport PR #13335: What's new 7.16.28fcdcd3
Pin Jedi to <0.17.2.2486838
release 7.16.120bdc6f
fix conda buildDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Hi,
I tried to play with this and got the error. The notebook is the one from the examples.
After executing
%%async_run
N = 10**s
print(N)
the error appeared in the console.
ERROR:tornado.application:Uncaught exception in /ws/PYTHON---9c4c6b81-49b3-4977-9093-b04f5bbf3328
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tornado/websocket.py", line 412, in _run_callback
callback(*args, **kwargs)
File "/Users/sergey/.ipython/profile_default/startup/run_async/run_server.py", line 181, in on_message
data = json.loads(message)
File "/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 349, in loads
s = s.decode(detect_encoding(s), 'surrogatepass')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
I used Jupyter Notebook 5.0.0 on Python 3.6 on MacOS