Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38137
| From | Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: autoflush on/off |
| Date | 2013-02-04 19:24 +0100 |
| Message-ID | <sva5u9-uek.ln1@satorlaser.homedns.org> (permalink) |
| References | <mailman.1326.1359997988.2939.python-list@python.org> |
Am 04.02.2013 18:12, schrieb Jabba Laci: > autoflush_on = False > > def unbuffered(): > """Switch autoflush on.""" > global autoflush_on > # reopen stdout file descriptor with write mode > # and 0 as the buffer size (unbuffered) > if not autoflush_on: > sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) > autoflush_on = True Note that you have two file objects (one not reachable any more) both writing to the same file descriptor. This also means you should first flush sys.stdout before changing it, otherwise it might still contain unflushed data. > I call unbuffered() once and it works well. However, when this loop is > over, I'd like to set the output back to buffered. How to do that? Just set sys.stdout back to the original value. OTOH, also check if you can't tell sys.stdout not to buffer. > As far as I remember, in Perl it was simply $| = 1 and $| = 0. "simply" ... ;) Uli
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
autoflush on/off Jabba Laci <jabba.laci@gmail.com> - 2013-02-04 18:12 +0100 Re: autoflush on/off garabik-news-2005-05@kassiopeia.juls.savba.sk - 2013-02-04 18:51 +0000 Re: autoflush on/off Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-02-04 19:24 +0100
csiph-web