Subtle output flushing issue in Python 3.4
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 190
- Avg merge
- 8m
- Merged PRs (30d)
- 13
Description
I just tracked down and annoying behavior change that we got in using Pyflakes when we upgraded from Python 2 to Python 3 in the Zulip project. It's related to interleaving stdout and stderr from pyflakes.
Basically we have a little pyflakes wrapper, check_pyflakes, that excludes certain warnings we're not interested in, by sending stdout and stderr to a pipe. It suddenly stopped filtering lines correctly when we switched to Python 3, because we were interleaving the stdout/stderr output from pyflakes, and apparently in Python 3, the newline characters in the pyflakes output got interleaved wrong, and so the filtering filtered the wrong thing. i.e. with code like p = subprocess.Pipe(["pyflakes", ...], stdout=subprocess.PIPE, stderr=subprocess.STDOUT); for ln in p.readlines(): print(p), you'll end up with lines of pyflakes output like this:
b"zproject/settings.py:95: 'from .prod_settings import *' used; unable to detect undefined nameszerver/views/users.py:49:39: invalid syntax\n"
(there should have been a \n in nameszerver).
Here's the commit I just merged into Zulip working around this issue, with details on the specifics: https://github.com/zulip/zulip/commit/6de77db93fe20d747541309d952035f070a157f6
Since I have found that needing to add a sys.stdout.flush() is a common type of new bug when switching to Python 3, I figured I'd report this, since I think the reason this stopped working is that Pyflakes needs such a statement added somewhere, and fixing this might save other folks moving to Python 3 some pain.
I'm happy to provide more details on how to reproduce, but I think it should be easy to do with the subprocess invocation that we have in the pre-6de77db9 world.
Thanks for a great tool, and I hope this report helps!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported check_pyflakes subprocess invocation and compare how Pyflakes writes interleaved stdout and stderr under Python 3.4. Use the Zulip workaround commit 6de77db93fe20d747541309d952035f070a157f to reproduce the filtering failure and identify the relevant Pyflakes entry point. Done means output lines remain correctly separated when consumed through a merged stdout/stderr pipe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100