Skip to content

Add support for nested py_capture_output() calls. #1564

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

Merged
merged 2 commits into from
Mar 28, 2024

Conversation

t-kalinowski
Copy link
Member

This adds support for nested py_capture_output() calls. I.e.,

py_capture_output({
  py_capture_output({
    py_run_string("print('hello')")
  })
})

See the included tests for a fuller example.

The issue with the previous implementation was discovered while investigating a segfault in the Keras testsuite, which would in some situations setup multiple py_capture_output() contexts. When that happened, the reference to the original sys.stdout would be lost permanently, resulting in no further output, and a cryptic R error message each time flush_std_buffers() was invoked from C++ functions or from the R top-level task callback.

@t-kalinowski t-kalinowski merged commit 09140b9 into main Mar 28, 2024
t-kalinowski added a commit to rstudio/keras3 that referenced this pull request Mar 28, 2024
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.

1 participant