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

potential fix for windows interrupts #1753

Merged
merged 7 commits into from
Feb 28, 2025
Merged

Conversation

kevinushey
Copy link
Collaborator

No description provided.

@t-kalinowski
Copy link
Member

Many thanks @kevinushey! I was really stumped on the issue with interrupts on Windows in Rstudio IDE, and this helps tremendously.

Do you think it's ready to merge?

else
tmp = PyObject_CallMethod(sys_stdout, "flush", NULL);
// try to invoke flush method
if (!PyObject_HasAttrString(buffer, "flush"))
Copy link
Member

@t-kalinowski t-kalinowski Feb 28, 2025

Choose a reason for hiding this comment

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

This probably doesn't matter, but I noticed in the python sources that PyObject_HasAttr() just calls PyObject_GetAttr() and then checks if an exception was raised. It's trivial, but we're on a hot code path here and the approach seems unnecessarily expensive if we're going to immediately fetch the attr again right after this in the common case, and we've already established an error-catching scope.

More relevant however, is that flush should always be present.
sys.stdout and sys.stderr are supposed to be a file object, and the abstract io base class defines this mixin method always: https://docs.python.org/3/library/io.html#io.IOBase (the method does nothing for output streams where flushing doesn't apply)

If flush missing, I think we should emit some error output, because it indicates that something is "wrong".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW we have this code that apparently expects stdout to be null in some scenarios.

https://github.com/rstudio/reticulate/blob/bugfix/windows-interrupts/R/output.R#L9-L13

@t-kalinowski t-kalinowski merged commit 84a4760 into main Feb 28, 2025
16 checks passed
@t-kalinowski
Copy link
Member

Thank you very much!

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