Skip to main content

Capture and redir ray logs in Jupyter Notebook.

Project description

Ray Log Notebook

This is a tiny FIX for Ray to display logs under the last executed cell instead of ray.init() cell.

Q: Why would this happen?
A: Ipykernel captures thread output and redir to the cell where thread is created. This is desired in some scenarios, but definitely not for Ray, whose logging thread is created upon ray.init() initialization.

Q: How can you fix this?
A: Utilizing IPython Events and mock Ray's internal log event handler. This may be unstable because we depend on Ray's non-public API. In normal mode, Ray would log by emitting logs to global_worker_stdstream_dispatcher, replacing the original handler with ours just works. For client mode, things get trickier. client_worker's LogStreamClient log_client would receive remote log stream by gRPC and print to stdout/stderr. We directly mock replace the stdstream method of that LogStreamClient instance. There may be more robust and non-intrusive ways to do it, for example capturing the ray.init() cell output.

Q: How can I use this? A: As simple as:

% cell 1
import ray
ray.init()

% cell 2
import ray_log_notebook
ray_log_notebook.enable()

% cell 3
@ray.remote
def test_print():
    print("Woola!")

await test_print.remote()

before after

Logs will always go to the last executed cell, instead of where the Ray Tasks are created.

Tested on Python 3.13 and Ray 2.50.0, generally should work but I don't have much time to test.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ray_log_notebook-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ray_log_notebook-0.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file ray_log_notebook-0.0.1.tar.gz.

File metadata

  • Download URL: ray_log_notebook-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.3

File hashes

Hashes for ray_log_notebook-0.0.1.tar.gz
Algorithm Hash digest
SHA256 08479b73309774d5937efba19c9296da122250cf8dcbaec93b7c51171fc01e1f
MD5 4f2947a0fd513541e62930a1fe2205f7
BLAKE2b-256 c83318a08d363f28a04b66cee2a26c955a967f6a443fa40a9af9f90e45655fd6

See more details on using hashes here.

File details

Details for the file ray_log_notebook-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ray_log_notebook-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32f6208b692cf6f5feaa5fe75adf0332f43f5465a9d2c6433cd1270234a9a97a
MD5 dd847678277a6391791de2326ff11114
BLAKE2b-256 9c02820ba7904b34eb85bf64d0f27187915ea7c240c67414fefb3fe4f5277737

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page