Skip to content

Commit 97d3292

Browse files
committed
fix OutStream hooks not being called
1 parent cb3ab6b commit 97d3292

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ipykernel/iostream.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import atexit
99
import contextvars
10+
import functools
1011
import io
1112
import os
1213
import sys
@@ -620,10 +621,19 @@ def flush(self):
620621
else:
621622
self._flush()
622623

624+
@property
623625
def _flush(self):
626+
"""Prepare _flush_impl partial to be scheduled on the IO thread.
627+
628+
This indirection is necessary to ensure _flush_impl calls hooks
629+
registered from the current thread (as they are thread-local).
630+
"""
631+
return functools.partial(self._flush_impl, self._hooks)
632+
633+
def _flush_impl(self, hooks=()):
624634
"""This is where the actual send happens.
625635
626-
_flush should generally be called in the IO thread,
636+
_flush_impl should generally be called in the IO thread,
627637
unless the thread has been destroyed (e.g. forked subprocess).
628638
"""
629639
self._flush_pending = False
@@ -648,7 +658,7 @@ def _flush(self):
648658
# Each transform either returns a new
649659
# message or None. If None is returned,
650660
# the message has been 'used' and we return.
651-
for hook in self._hooks:
661+
for hook in hooks:
652662
msg = hook(msg)
653663
if msg is None:
654664
return

0 commit comments

Comments
 (0)