Skip to content

Do not write to stdout on debugging #1892

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vnmabus
Copy link

@vnmabus vnmabus commented May 14, 2025

Write to stderr instead of stdout when changing Matplotlib interactivity. Otherwise the doctests will fail when debugging them.

I tested this by changing it manually on my VSCode instance 😁.

Write to stderr instead of stdout when changing Matplotlib interactivity. Otherwise the doctests will fail when debugging them.

I tested this by changing it manually on my VSCode instance 😁.
@vnmabus vnmabus requested a review from a team as a code owner May 14, 2025 17:16
@rchiodo
Copy link
Contributor

rchiodo commented May 14, 2025

I think this is okay, but what is failing with writing to stdout?

@vnmabus
Copy link
Author

vnmabus commented May 14, 2025

what is failing with writing to stdout?

Whatever you write to stdout appears in the doctest output, and thus it does not match the expected output anymore, failing the test.

@@ -140,11 +140,11 @@ def activate_matplotlib(enable_gui_function):
if is_interactive:
enable_gui_function(gui)
if not matplotlib.is_interactive():
sys.stdout.write("Backend %s is interactive backend. Turning interactive mode on.\n" % backend)
sys.stderr.write("Backend %s is interactive backend. Turning interactive mode on.\n" % backend)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this shouldn't write to either. It should probably write to the log instead.

That would be something like this instead:

Suggested change
sys.stderr.write("Backend %s is interactive backend. Turning interactive mode on.\n" % backend)
pydev_log.debug("Backend %s is interactive backend. Turning interactive mode on.\n" % backend)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course after importing pdev_log. Maybe that causes some import problems though and it's why this code was writing to stdout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to stderr because I saw it writing to stderr in other places in the same file, but logging is fine to me, as long as it does not end in stdout.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not sure why it's writing to stderr instead of log elsewhere. I believe this code was originally a port from somewhere else and maybe whomever ported it didn't bother to make it write to the log instead.

@rchiodo
Copy link
Contributor

rchiodo commented May 14, 2025

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants