Skip to content

Commit

Permalink
[core][logging][ipython] Fix log buffering when consecutive runs with…
Browse files Browse the repository at this point in the history
…in ray log dedup window (#37134)
  • Loading branch information
rickyyx authored Jul 6, 2023
1 parent 9b6a449 commit 10e11f9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions python/ray/_private/ray_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ def setup_component_logger(
return logger


def run_callback_on_events_in_ipython(event: str, cb: Callable):
"""
Register a callback to be run after each cell completes in IPython.
E.g.:
This is used to flush the logs after each cell completes.
If IPython is not installed, this function does nothing.
Args:
cb: The callback to run.
"""
try:
from IPython import get_ipython

ipython = get_ipython()
# Register a callback on cell completion.
if ipython is not None:
ipython.events.register(event, cb)
except ImportError:
pass


"""
All components underneath here is used specifically for the default_worker.py.
"""
Expand Down Expand Up @@ -226,6 +248,8 @@ def __init__(
self.recent: Dict[str, DedupState] = {}
self.timesource = _timesource or (lambda: time.time())

run_callback_on_events_in_ipython("post_execute", self.flush)

def deduplicate(self, batch: LogBatch) -> List[LogBatch]:
"""Rewrite a batch of lines to reduce duplicate log messages.
Expand Down

0 comments on commit 10e11f9

Please sign in to comment.