Skip to content

Do not write to stdout on debugging#1892

Open
vnmabus wants to merge 1 commit into
microsoft:mainfrom
vnmabus:patch-1
Open

Do not write to stdout on debugging#1892
vnmabus wants to merge 1 commit into
microsoft:mainfrom
vnmabus:patch-1

Conversation

@vnmabus

@vnmabus vnmabus commented May 14, 2025

Copy link
Copy Markdown

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

rchiodo commented May 14, 2025

Copy link
Copy Markdown
Contributor

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

@vnmabus

vnmabus commented May 14, 2025

Copy link
Copy Markdown
Author

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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

rchiodo commented May 14, 2025

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
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