#29533: Flushing stdout in django-admin command
-------------------------------------+-------------------------------------
Reporter: David | Owner: nobody
Ruggles |
Type: New | Status: new
feature |
Component: Core | Version: 2.0
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I'm writing django-admin commands that are used interactively on the
command line. According to the documentation, I should use
{{{
self.stdout.write
}}}
instead of
{{{
print
}}}
I ran into a case where I wanted to print multiple dots on a line to
provide a rudimentary progress indicator. I set
{{{
ending=''
}}}
and quickly discovered that the output is buffered. With print I could do
{{{
print('.', end='', flush=True)
}}}
and it would work. Or I could do
{{{
sys.stdout.flush()
}}}
so I tried
{{{
self.stdout.flush()
}}}
with no change. I dug into the code and found that the flush method is
simply coming from **IOBase** and is a pass. So I modified
**OutputWrapper** by adding the following method:
{{{
def flush(self):
self._out.flush()
}}}
This did want I wanted, but could there be unintended consequences? If
not, would this be a reasonable patch?
--
Ticket URL: <https://code.djangoproject.com/ticket/29533>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.f8e41349a90736a18e0dcf8f585c262c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.