sys.stdout linebuffered

B

Benjamin Niemann

I start a long running script like this (unix):
nohup foo.py > foo.log &

Now Python thinks sys.stdout should not be
line buffered. How can I force linebuffering?

I want to see the log file while the script is
still running.

I don't like this solution (Wrapping sys.stdout
with an own class)

http://groups.google.de/groups?hl=de&lr=&ie=UTF-8&[email protected]

The "-u" switch is not an option.
Even if you use
#!/usr/bin/python -u
in your script?
 
P

Peter Hansen

Thomas said:
I start a long running script like this (unix):

nohup foo.py > foo.log & [snip]
The "-u" switch is not an option.

That statement is suspect, and like Benjamin I wonder whether
it really is true. Nevertheless, in the unlikely case that you
absolutely cannot use the -u switch, look at the description of
that option in the output of "python -h" and use the environment
variable mentioned there instead.

-Peter
 
T

Thomas Guettler

Am Wed, 26 May 2004 09:40:01 -0400 schrieb Peter Hansen:
Thomas said:
I start a long running script like this (unix):

nohup foo.py > foo.log & [snip]
The "-u" switch is not an option.

That statement is suspect, and like Benjamin I wonder whether
it really is true.

I like to use #!/usr/bin/env

===> cat minus-u.py
#!/usr/bin/env python -u

===> ./minus-u.py
/usr/bin/env: python -u: No such file or directory
Nevertheless, in the unlikely case that you
absolutely cannot use the -u switch, look at the description of
that option in the output of "python -h" and use the environment
variable mentioned there instead.

The environment variable has the drawback,
that I need to set it before every call to this
script. Other scripts should not be unbuffered.

Thomas
 
P

Peter Hansen

Thomas said:
I like to use #!/usr/bin/env

===> cat minus-u.py
#!/usr/bin/env python -u

===> ./minus-u.py
/usr/bin/env: python -u: No such file or directory

Consider using /usr/bin/python instead?
The environment variable has the drawback,
that I need to set it before every call to this
script. Other scripts should not be unbuffered.

If this is the only script with special needs, why not
just create a separate shell script which invokes python
on the other script directly?

#!/bin/sh
/usr/bin/env python -u specialscript.py


-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,047
Members
47,646
Latest member
xayaci5906

Latest Threads

Top