Skip to content

Commit

Permalink
fix capturing display publisher to work with teeing
Browse files Browse the repository at this point in the history
  • Loading branch information
smacke committed Feb 25, 2024
1 parent be061c2 commit 3e83336
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/ipyflow/utils/ipython_utils.py
Expand Up @@ -150,6 +150,11 @@ def set_parent(self, *args, **kwargs) -> None:
self.pub2.set_parent(*args, **kwargs)


class TeeCompatibleCapturingDisplayPublisher(CapturingDisplayPublisher):
def clear_output(self, wait=False):
self.outputs.clear()


class CaptureOutputTee:
"""
Context manager for capturing and replicating stdout/err and rich display publishers.
Expand Down Expand Up @@ -186,7 +191,7 @@ def __enter__(self) -> CapturedIO:
sys.stderr = Tee(sys.stderr, stderr) # type: ignore
if self.display and self.shell is not None:
self.save_display_pub = self.shell.display_pub
capture_display_pub = CapturingDisplayPublisher()
capture_display_pub = TeeCompatibleCapturingDisplayPublisher()
outputs = capture_display_pub.outputs
self.shell.display_pub = TeeDisplayPublisher(
self.save_display_pub, capture_display_pub
Expand Down

0 comments on commit 3e83336

Please sign in to comment.