Skip to content

Commit

Permalink
Use PID to assign rainbow colors to console output prefixes. (ray-pro…
Browse files Browse the repository at this point in the history
…ject#26900)

When I use tune.run, different processes are distinguished by the number corresponding to their pid:
  • Loading branch information
ethanabrooks committed Apr 26, 2023
1 parent aac0fa0 commit bb38c8b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions doc/source/ray-observability/ray-logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ This produces the following output:
(MyActor(index=2) pid=482120) hello there
(MyActor(index=1) pid=482119) hello there
Coloring Actor log prefixes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default Ray prints Actor logs prefixes in light blue:
Users may instead activate multi-color prefixes by setting the environment variable ``RAY_COLOR_PREFIX=1``.
This will index into an array of colors modulo the PID of each process.

.. image:: images/images/coloring-actor-log-prefixes.png
:align: center

Distributed progress bars (tqdm)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
22 changes: 22 additions & 0 deletions python/ray/_private/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,28 @@ def color_for(data: Dict[str, str], line: str) -> str:
return colorama.Style.BRIGHT + colorama.Fore.YELLOW
else:
return colorama.Style.BRIGHT + colorama.Fore.CYAN
elif os.getenv("RAY_COLOR_PREFIX") == "1":
colors = [
# colorama.Fore.BLUE, # Too dark
colorama.Fore.MAGENTA,
colorama.Fore.CYAN,
colorama.Fore.GREEN,
# colorama.Fore.WHITE, # Too light
# colorama.Fore.RED,
colorama.Fore.LIGHTBLACK_EX,
colorama.Fore.LIGHTBLUE_EX,
# colorama.Fore.LIGHTCYAN_EX, # Too light
# colorama.Fore.LIGHTGREEN_EX, # Too light
colorama.Fore.LIGHTMAGENTA_EX,
# colorama.Fore.LIGHTWHITE_EX, # Too light
# colorama.Fore.LIGHTYELLOW_EX, # Too light
]
pid = data.get("pid", 0)
try:
i = int(pid)
except ValueError:
i = 0
return colors[i % len(colors)]
else:
return colorama.Fore.CYAN

Expand Down

0 comments on commit bb38c8b

Please sign in to comment.