Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Add filtering logic for stream data and constraint setuptools version #496

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/posix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ jupyter_client>=7.4.9,<9
pyzmq>=24.0.0
wurlitzer>=1.0.3
pyxdg>=0.26
setuptools<71.0
1 change: 1 addition & 0 deletions requirements/windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ipykernel>=6.29.3,<7
ipython>=8.12.2,<9
jupyter_client>=7.4.9,<9
pyzmq>=24.0.0
setuptools<71.0
50 changes: 50 additions & 0 deletions spyder_kernels/console/outstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"""
Custom Spyder Outstream class.
"""
import os
import sys

from ipykernel.iostream import OutStream

Expand All @@ -20,3 +22,51 @@ def __init__(self, session, pub_thread, name, pipe=None, echo=None, *,
watchfd=True):
super().__init__(session, pub_thread, name, pipe,
echo=echo, watchfd=watchfd, isatty=True)

def _flush(self):
"""This is where the actual send happens.

_flush should generally be called in the IO thread,
unless the thread has been destroyed (e.g. forked subprocess).

NOTE: Overrided method to be able to filter messages.
See spyder-ide/spyder#22181
"""
self._flush_pending = False
self._subprocess_flush_pending = False

if self.echo is not None:
try:
self.echo.flush()
except OSError as e:
if self.echo is not sys.__stderr__:
print(f"Flush failed: {e}", file=sys.__stderr__)

for parent, data in self._flush_buffers():
# Messages that will not be printed to the console. This allows us
# to deal with issues such as spyder-ide/spyder#22181
filter_messages = ["Parent poll failed."]
dalthviz marked this conversation as resolved.
Show resolved Hide resolved

if data and not any(
[message in data for message in filter_messages]
):
# FIXME: this disables Session's fork-safe check,
# since pub_thread is itself fork-safe.
# There should be a better way to do this.
self.session.pid = os.getpid()
content = {"name": self.name, "text": data}
msg = self.session.msg("stream", content, parent=parent)

# Each transform either returns a new
# message or None. If None is returned,
# the message has been 'used' and we return.
for hook in self._hooks:
msg = hook(msg)
if msg is None:
return

self.session.send(
self.pub_thread,
msg,
ident=self.topic,
)
Loading