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 — fix I/O operation on closed file error with CliRunner and echo_via_pager by ChrisPappalardo · Pull Request #3482 · pallets/click

Conversation

@ChrisPappalardo

@ChrisPappalardo ChrisPappalardo commented May 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #3449 by adding a thinner version of MaybeStripAnsi that is not subclassed from io.TextIOWrapper when handling sys.stdout and sys.stderr streams.

Sorry, something went wrong.

Uh oh!

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

All reactions
@davidism

davidism commented May 19, 2026

Copy link
Copy Markdown
Member

Seems like we should be able to keep the single wrapper and override the close method to do nothing in the problematic case.

All reactions

Sorry, something went wrong.

Uh oh!

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

@davidism davidism added this to the 8.4.1 milestone May 21, 2026
davidism
davidism reviewed May 21, 2026
View reviewed changes
Comment thread src/click/_termui_impl.py Outdated
# while text-only streams are yielded as-is.
if _has_binary_buffer(stream):
# route stdout and stderr through a thinner wrapper
is_std = stream is sys.stdout or stream is sys.stderr

@davidism davidism May 21, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@Rowlando13 this is a good example of why I think the whole text/binary stream handling in Click is not needed. It's completely bypassed for stdin/stdout here, and all tests still pass. Fairly sure these checks were for Python 2/3 compat, but I didn't have enough time to check it all when I removed most of the compat years ago.

Sorry, something went wrong.

Uh oh!

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

kdeldycke reacted with eyes emoji
All reactions
  • 👀 1 reaction

@kdeldycke kdeldycke May 23, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is being discussed at #3481

Sorry, something went wrong.

Uh oh!

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

All reactions
@davidism

davidism commented May 22, 2026

Copy link
Copy Markdown
Member

After investigating from my initial comment, it does look like we need to wrap the stream returned by nullpager instead of this. The wrapper should pass everything through, except override close to do nothing. Will work on this tonight or tomorrow.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ChrisPappalardo @davidism
pager doesn't close std streams
becbde5
@davidism
davidism force-pushed the fix-io-operation-on-closed-file-error branch from 2cf8e01 to becbde5 Compare May 22, 2026 03:36
@davidism
davidism changed the base branch from main to stable May 22, 2026 03:37
@davidism

davidism commented May 22, 2026

Copy link
Copy Markdown
Member

Also needed to make sure stream.buffer wouldn't close either, since get_pager_file would wrap stream.buffer instead of stream. This all seems a bit messy, probably something that can be cleaned up eventually. @Rowlando13 @kdeldycke.

All reactions

Sorry, something went wrong.

Uh oh!

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

@davidism
davidism merged commit 5ee8e31 into pallets:stable May 22, 2026
11 checks passed

Uh oh!

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

@kdeldycke kdeldycke mentioned this pull request May 22, 2026
Pre-8.4.2 release changelog and doc fixes #3498
Merged
@kdeldycke kdeldycke added bug test runner CliRunner and Click's test utilities feature labels May 22, 2026
@kdeldycke

kdeldycke commented May 22, 2026

Copy link
Copy Markdown
Collaborator

Also needed to make sure stream.buffer wouldn't close either, since get_pager_file would wrap stream.buffer instead of stream. This all seems a bit messy, probably something that can be cleaned up eventually. @Rowlando13 @kdeldycke.

Also CC @AndreasBackx for the missing tests in #3405 covering #1572

All reactions

Sorry, something went wrong.

Uh oh!

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

This was referenced May 22, 2026
Activate nightly workflow for random and stress tests #3500
Merged
Remove Python 2 utilities and little used utilities #3481
Closed
@rickardvh rickardvh mentioned this pull request May 25, 2026
[Evaluation Epic]: Orchestrated long-horizon repo episodes with restart and agent switching rickardvh/agentic-workspace#1124
Closed
kdeldycke added a commit to kdeldycke/click that referenced this pull request May 29, 2026
@kdeldycke
Fix quoting, add PR references
2b8ba4f
pallets#3493
pallets#3482
@kdeldycke kdeldycke mentioned this pull request May 29, 2026
Do not let the GC close a borrowed stdout #3533
Merged
@kdeldycke

kdeldycke commented May 29, 2026

Copy link
Copy Markdown
Collaborator

This fix was not complete. I proposed one at #3533 . @ChrisPappalardo can you review and test it?

All reactions

Sorry, something went wrong.

Uh oh!

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

kdeldycke added a commit to kdeldycke/click that referenced this pull request May 29, 2026
@kdeldycke
Do not let the GC close a borrowed stdout
8b6441f
Complete the "I/O operation on closed file" fix from pallets#3482, and definitely addresses pallets#3449.
kdeldycke added a commit to kdeldycke/click that referenced this pull request Jun 3, 2026
@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.
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@kdeldycke kdeldycke kdeldycke left review comments
@davidism davidism davidism left review comments

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.1

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.

3 participants

@ChrisPappalardo @davidism @kdeldycke
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.