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

Ensure that stderr/stdout has flush attr before calling it #1248

Merged
merged 2 commits into from Mar 23, 2022
Merged

Ensure that stderr/stdout has flush attr before calling it #1248

merged 2 commits into from Mar 23, 2022

Conversation

moble
Copy link
Contributor

@moble moble commented Sep 13, 2021

The recent commit 63f427b (which was evidently in response to #1177) is leading to errors in some cases. It turns out that sys.stdout and sys.stderr can be None in some cases, as mentioned in the note at the bottom of this section in the python docs. (This is news to me, and the cases I've encountered this in are not like what the docs suggest.) When they are None an error occurs inside tqdm because obviously None.flush() does not exist.

This PR just checks that stderr and stdout actually have a flush attribute before using that attribute. Note that we can't just reuse fp_flush because the point of #1177 was that both stdout and stderr need to be flushed.


For reference, I've encountered the bug on two systems:

  1. Ubuntu 20.04.3 LTS with Python 3.9.6 and tqdm 4.62.2 (via github actions, for which the traceback is here)
  2. Debian 4.19.160-2 with Python 3.7.3. This is through a bug report on an unrelated repo, so I can't actually check the tqdm version, but I'll bet it's >=4.61.2.

@moble
Copy link
Contributor Author

moble commented Oct 21, 2021

@casperdcl Anything I can do to help move this along?

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 14, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.03%.

Quality metrics Before After Change
Complexity 25.85 😞 25.85 😞 0.00
Method Length 71.76 🙂 72.00 🙂 0.24 👎
Working memory 15.16 😞 15.16 😞 0.00
Quality 47.27% 😞 47.24% 😞 -0.03% 👎
Other metrics Before After Change
Lines 1558 1558 0
Changed files Quality Before Quality After Quality Change
tqdm/std.py 47.27% 😞 47.24% 😞 -0.03% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
tqdm/std.py tqdm.format_meter 73 ⛔ 572 ⛔ 29 ⛔ 2.09% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.__init__ 53 ⛔ 553 ⛔ 39 ⛔ 3.16% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.pandas 53 ⛔ 409 ⛔ 13 😞 15.07% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.pandas.inner_generator 26 😞 196 😞 13 😞 31.76% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.update 27 😞 154 😞 14 😞 33.57% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@dtrifiro
Copy link

This also happens with gitbash on Windows, see iterative/dvc#7465

@casperdcl casperdcl changed the base branch from master to devel March 23, 2022 23:06
Copy link
Sponsor Member

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

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

Ah I think the PR description is wrong.

This PR does not fix sys.std{err,out} == None (sys.std{err,out}.write() would fail if it was really None).

I think this PR fixes libraries which monkey-patch sys.std{err,out} removing their flush() method.

@casperdcl casperdcl added p0-bug-critical ☢ Exception rasing to-merge ↰ Imminent c1-quick 🕐 Complexity low labels Mar 23, 2022
@casperdcl casperdcl added this to Next Release in Casper Mar 23, 2022
@casperdcl casperdcl merged commit 165a23a into tqdm:devel Mar 23, 2022
Casper automation moved this from Next Release to Done Mar 23, 2022
@casperdcl
Copy link
Sponsor Member

thanks! Sorry for the long delay 🙏

@casperdcl
Copy link
Sponsor Member

/tag v4.63.1 165a23a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing to-merge ↰ Imminent
Projects
Casper
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants