Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/albertz/background-zmq-ipython
Background ZMQ IPython/Jupyter kernel
https://github.com/albertz/background-zmq-ipython
ipython jupyter python
Last synced: 25 days ago
JSON representation
Background ZMQ IPython/Jupyter kernel
- Host: GitHub
- URL: https://github.com/albertz/background-zmq-ipython
- Owner: albertz
- License: bsd-2-clause
- Created: 2019-02-01T14:48:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-17T09:48:29.000Z (over 1 year ago)
- Last Synced: 2024-09-29T00:01:45.568Z (about 1 month ago)
- Topics: ipython, jupyter, python
- Language: Python
- Size: 36.1 KB
- Stars: 17
- Watchers: 3
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
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.jsonNow, 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:
* `pydbattach `_
* `Twisted SSH `_
(`example code `__)
* ``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.