GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Do not let the GC close a borrowed `stdout` by kdeldycke · Pull Request #3533 · pallets/click

Conversation

@kdeldycke

@kdeldycke kdeldycke commented May 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Complete the partial fix proposed in #3482 for #3449.

This PR reproduce the case highlighted in #3449 where a stream that is not managed by the pager machinery is closed by it unconditionally.

As extra bonuses:

  • replace _SkipClose with utils.KeepOpenFile
  • document KeepOpenFile
  • eliminate a dead elif isinstance(stream, t.BinaryIO) branch as non-buffered text streams can be yielded as-is

This is a follow up of #3482 which is a follow up of #3405 which is a follow up of #1572.

CC @ChrisPappalardo @AndreasBackx @craigds

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kdeldycke kdeldycke added the bug label May 29, 2026
@kdeldycke kdeldycke added this to the 8.4.2 milestone May 29, 2026
@kdeldycke kdeldycke mentioned this pull request May 29, 2026
fix I/O operation on closed file error with CliRunner and echo_via_pager #3482
Merged
@kdeldycke kdeldycke added the test runner CliRunner and Click's test utilities feature label May 29, 2026
@kdeldycke kdeldycke mentioned this pull request May 29, 2026
"I/O operation on closed file" error with CliRunner and echo_via_pager under 8.4 #3449
Closed
@kdeldycke kdeldycke linked an issue May 29, 2026 that may be closed by this pull request
"I/O operation on closed file" error with CliRunner and echo_via_pager under 8.4 #3449
Closed
@kdeldycke
kdeldycke requested review from AndreasBackx, Rowlando13 and davidism May 29, 2026 13:43
@davidism

davidism commented May 29, 2026

Copy link
Copy Markdown
Member

I realized there's already utils.KeepOpenFile which does all the dunder stuff. Let's get rid of _SkipClose, it's redundant. (Again noticing just how many wrappers we have.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davidism

davidism commented May 29, 2026

Copy link
Copy Markdown
Member

There also seems to be way too many context managers and levels of indirection for the pager machinery at this point. I'm not sure how we got here, but I'd sure love to refactor and simplify it somehow.

kdeldycke reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke

kdeldycke commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

I realized there's already utils.KeepOpenFile which does all the dunder stuff. Let's get rid of _SkipClose, it's redundant. (Again noticing just how many wrappers we have.)

TIL. Let me play a bit with utils.KeepOpenFile to see how it works...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke kdeldycke changed the title Complete the "I/O operation on closed file" fix from #3482 Do not let the GC close a borrowed stdout May 29, 2026
@kdeldycke

kdeldycke commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

I realized there's already utils.KeepOpenFile which does all the dunder stuff. Let's get rid of _SkipClose, it's redundant. (Again noticing just how many wrappers we have.)

Seems to do the trick! Thanks for the hint! :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke

kdeldycke commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

There also seems to be way too many context managers and levels of indirection for the pager machinery at this point. I'm not sure how we got here, but I'd sure love to refactor and simplify it somehow.

This part of Click is insane. The only thing that gives me confidence is the amount of collected cases from users that we transformed into unittests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke
kdeldycke force-pushed the fix-pager-stream-close branch from 72c07e8 to 8b6441f Compare May 29, 2026 14:32
@kdeldycke

kdeldycke commented May 29, 2026

Copy link
Copy Markdown
Collaborator Author

I squashed the commits, this is ready to be reviewed. I'll go down the pager rabbit hole in other PRs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke kdeldycke mentioned this pull request May 29, 2026
Support incremental output in the pager #3534
Merged
@Rowlando13

Rowlando13 commented May 31, 2026

Copy link
Copy Markdown
Member

@ChrisPappalardo can you review this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frenzymadness

frenzymadness commented Jun 1, 2026

Copy link
Copy Markdown

I can confirm that this fixes all the I/O problems for us. We still have 30 failed tests, but I haven't had time to investigate them yet.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChrisPappalardo

ChrisPappalardo commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

@ChrisPappalardo can you review this?

LGTM - this has evolved pretty far from my initial PR, but I think this approach works

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke
Do not let the GC close a borrowed stdout
051bb0f
Complete the "I/O operation on closed file" fix from pallets#3482, and definitely addresses pallets#3449.
@kdeldycke
kdeldycke force-pushed the fix-pager-stream-close branch from 8b6441f to 051bb0f Compare June 3, 2026 11:49
@Rowlando13
Rowlando13 merged commit 4df304c into pallets:stable Jun 3, 2026
11 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke
kdeldycke deleted the fix-pager-stream-close branch June 4, 2026 08:29
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@AndreasBackx AndreasBackx Awaiting requested review from AndreasBackx
@davidism davidism Awaiting requested review from davidism
@Rowlando13 Rowlando13 Awaiting requested review from Rowlando13

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

test runner CliRunner and Click's test utilities feature

Projects

None yet

Milestone

8.4.2

Development

Successfully merging this pull request may close these issues.

"I/O operation on closed file" error with CliRunner and echo_via_pager under 8.4

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@kdeldycke @davidism @Rowlando13 @frenzymadness @ChrisPappalardo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.