Background ZMQ IPython/Jupyter kernel
Project description
Run some IPython ZMQ kernel in the background, without an interactive shell. You can connect to that kernel remotely via ZMQ.
Installation (package is on PyPI):
pip install background_zmq_ipython
Usage:
import background_zmq_ipython background_zmq_ipython.init_ipython_kernel()
The kernel will then run in the background in its own thread. The init will print some message similar to this on stdout:
To connect another client to this IPython kernel, use: jupyter console --existing kernel-1111.json
Now, after you connected, how to access globals from the main module? E.g. let’s say there is a variable a.
sys.modules["__main__"].a should work. Via sys.modules, you can access all the imported modules. Or just do import mod again.
Get the stack of all/other frames via sys._current_frames(), and there you can access the globals from other threads as well.
You can provide user_ns to init_ipython_kernel, e.g:
init_ipython_kernel(user_ns=globals())
or:
init_ipython_kernel(user_ns={"main_globals": globals()})
or:
init_ipython_kernel(user_ns={"a": a})
Alternatives / related links:
IPython.embed_kernel in a background thread (example code). This has some issues (e.g. here; messing around with sys.stdout etc).
This code was introduced in this StackOverflow question, and also discussed in this IPython GitHub issue #8097, but it has become outdated, so this project provides a rewrite / updated code, and the goal was also an easy to install pip package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for background_zmq_ipython-1.20190928.182508.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7668b53d479ab0d226e05671cfd6b41034de6b067b8646ae373b63855665c0a |
|
MD5 | 9c7f0079d84c2a8b109f194a4a1cbe9f |
|
BLAKE2b-256 | b5fae7185a3594f93710d4b476e8fe7390e3bf6fab19c93d655ba78ccb0fb30c |