Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26992 > unrolled thread
| Started by | Helmut Jarausch <jarausch@skynet.be> |
|---|---|
| First post | 2012-08-13 15:16 +0000 |
| Last post | 2012-08-13 12:49 -0400 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
print(....,file=sys.stderr) buffered? Helmut Jarausch <jarausch@skynet.be> - 2012-08-13 15:16 +0000
Re: print(....,file=sys.stderr) buffered? Grant Edwards <invalid@invalid.invalid> - 2012-08-13 15:43 +0000
Re: print(....,file=sys.stderr) buffered? Helmut Jarausch <jarausch@skynet.be> - 2012-08-13 16:29 +0000
Re: print(....,file=sys.stderr) buffered? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-08-14 11:06 +0200
Re: print(....,file=sys.stderr) buffered? Jerry Hill <malaclypse2@gmail.com> - 2012-08-13 12:49 -0400
| From | Helmut Jarausch <jarausch@skynet.be> |
|---|---|
| Date | 2012-08-13 15:16 +0000 |
| Subject | print(....,file=sys.stderr) buffered? |
| Message-ID | <50291a41$0$3122$ba620e4c@news.skynet.be> |
Hi,
for tracing purposes I have added some print outs like
print('+++ before calling foo',file=sys.stderr)
x=foo(..)
print('--- after calling foo',
and within 'foo'
print('>>> entering foo ...',file=sys.stderr)
Now, when executing this, I always get
+++ before calling foo
--- after calling foo
>>> entering foo ...
When outputting to stderr from C/C++ it's guaranteed that the different
outputs appear in the same order as they have been generated.
Is this guarantee no more valid in Python 3.2 ?
Many thanks for a comment,
Helmut.
(That's a single-threaded application)
[toc] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2012-08-13 15:43 +0000 |
| Message-ID | <k0b7b2$h1j$1@reader1.panix.com> |
| In reply to | #26992 |
On 2012-08-13, Helmut Jarausch <jarausch@skynet.be> wrote:
> Hi,
>
> for tracing purposes I have added some print outs like
>
> print('+++ before calling foo',file=sys.stderr)
> x=foo(..)
> print('--- after calling foo',
>
> and within 'foo'
> print('>>> entering foo ...',file=sys.stderr)
>
> Now, when executing this, I always get
>
> +++ before calling foo
> --- after calling foo
>>>> entering foo ...
>
> When outputting to stderr from C/C++ it's guaranteed that the different
> outputs appear in the same order as they have been generated.
You're not printing to stderr in the second print() call -- you're
printing to stdout. The two file objects have separate buffers and
may even be using two different buffering modes (e.g. line vs. block).
You can't interleave writes to stderr and stdout and assume order is
preserved unless you take specific steps (such as forcing them both to
be unbuffered or flushing them at certain points).
> Is this guarantee no more valid in Python 3.2 ?
If you write to stderr all three times, it should work the way you
want it to.
--
Grant Edwards grant.b.edwards Yow! ... I'm IMAGINING a
at sensuous GIRAFFE, CAVORTING
gmail.com in the BACK ROOM of a
KOSHER DELI --
[toc] | [prev] | [next] | [standalone]
| From | Helmut Jarausch <jarausch@skynet.be> |
|---|---|
| Date | 2012-08-13 16:29 +0000 |
| Message-ID | <50292b78$0$3122$ba620e4c@news.skynet.be> |
| In reply to | #26993 |
On Mon, 13 Aug 2012 15:43:31 +0000, Grant Edwards wrote:
> On 2012-08-13, Helmut Jarausch <jarausch@skynet.be> wrote:
>> Hi,
>>
>> for tracing purposes I have added some print outs like
>>
>> print('+++ before calling foo',file=sys.stderr)
>> x=foo(..)
>> print('--- after calling foo',
Sorry, this is a cut'n paste error. I did use
print('--- after calling foo',file=sys.stderr)
>>
>> and within 'foo'
>> print('>>> entering foo ...',file=sys.stderr)
>>
>> Now, when executing this, I always get
>>
>> +++ before calling foo --- after calling foo
>>>>> entering foo ...
>>
>> When outputting to stderr from C/C++ it's guaranteed that the different
>> outputs appear in the same order as they have been generated.
>
> You're not printing to stderr in the second print() call -- you're
> printing to stdout. The two file objects have separate buffers and may
> even be using two different buffering modes (e.g. line vs. block).
> You can't interleave writes to stderr and stdout and assume order is
> preserved unless you take specific steps (such as forcing them both to
> be unbuffered or flushing them at certain points).
>
>> Is this guarantee no more valid in Python 3.2 ?
>
> If you write to stderr all three times, it should work the way you want
> it to.
It seems it doesn't do so in my case.
Thanks,
Helmut.
[toc] | [prev] | [next] | [standalone]
| From | Alain Ketterlin <alain@dpt-info.u-strasbg.fr> |
|---|---|
| Date | 2012-08-14 11:06 +0200 |
| Message-ID | <871uj9rgfc.fsf@dpt-info.u-strasbg.fr> |
| In reply to | #26996 |
Helmut Jarausch <jarausch@skynet.be> writes:
> On Mon, 13 Aug 2012 15:43:31 +0000, Grant Edwards wrote:
>
>> On 2012-08-13, Helmut Jarausch <jarausch@skynet.be> wrote:
>>> Hi,
>>>
>>> for tracing purposes I have added some print outs like
>>>
>>> print('+++ before calling foo',file=sys.stderr)
>>> x=foo(..)
>>> print('--- after calling foo',
>
> Sorry, this is a cut'n paste error. I did use
> print('--- after calling foo',file=sys.stderr)
>
>>>
>>> and within 'foo'
>>> print('>>> entering foo ...',file=sys.stderr)
>>>
>>> Now, when executing this, I always get
>>>
>>> +++ before calling foo
>>> --- after calling foo
>>>>>> entering foo ...
This can't happen with "normal" code. Are you playing with lambdas or
generators here? Or anything else that could introduce lazyness?
-- Alain.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Hill <malaclypse2@gmail.com> |
|---|---|
| Date | 2012-08-13 12:49 -0400 |
| Message-ID | <mailman.3234.1344876569.4697.python-list@python.org> |
| In reply to | #26992 |
On Mon, Aug 13, 2012 at 11:16 AM, Helmut Jarausch <jarausch@skynet.be> wrote: > Now, when executing this, I always get > > +++ before calling foo > --- after calling foo >>>> entering foo ... Can you give us a piece of code we can run that produces this output for you? You gave us an outline in your original post, but it would be useful to have a self contained example that you can say reliably produces the unexpected output for you. Also, what environment, OS, and exact python version is this? Is the code being run in an IDE of some sort? Does the behavior change if you call your code directly from the command line? -- Jerry
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web