473,382 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

sys.stdout linebuffered

Hi,

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...3.fitlinxx.com

The "-u" switch is not an option.

Thomas

Jul 18 '05 #1
5 1929
> 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...3.fitlinxx.com

The "-u" switch is not an option.

Even if you use
#!/usr/bin/python -u
in your script?
Jul 18 '05 #2
Thomas Guettler wrote:
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
Jul 18 '05 #3
Am Wed, 26 May 2004 09:40:01 -0400 schrieb Peter Hansen:
Thomas Guettler wrote:
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

Jul 18 '05 #4
Thomas Guettler wrote:
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?
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.


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
Jul 18 '05 #5
"Thomas Guettler" <gu*****@thomas-guettler.de> writes:
Hi,

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...3.fitlinxx.com


Why? It appears to solve your problem!

Cheers,
mwh

--
I think if we have the choice, I'd rather we didn't explicitly put
flaws in the reST syntax for the sole purpose of not insulting the
almighty. -- /will on the doc-sig
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
4
by: Leon | last post by:
"stdout" is file object, it open mode is "w" and it have a close() fuction..... while it run close(), how to reopen it because I want to do rewrite it stdout content update
7
by: Mike | last post by:
I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout,...
10
by: Michael Gaab | last post by:
If I redirect stdout by using freopen("afile", "w", stdout); and then I closed stdout using, fclose(stdout), essentially I am just closing "afile". I have to reestablish what stdout originally...
9
by: Santtu Nyrhinen | last post by:
Hi, Let say that I have a function like void writeHello() { printf("Hello"); } Now I need to make an automated test fot that function. The test function returns 1 for successful and 0 for...
2
by: Greg Ercolano | last post by:
When I use os.popen(cmd,'w'), I find that under windows, the stdout of the child process disappears, instead of appearing in the DOS window the script is invoked from. eg: C:\type foo.py import...
5
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I wanna print the log to both the screen and file, so I simulatered a 'tee' class Tee(file): def __init__(self, name, mode): file.__init__(self, name, mode) self.stdout = sys.stdout...
4
by: hg | last post by:
Hi, I have the following ********************* C extention - redir.c #include "Python.h" PyObject * test_redir_test(PyObject *self) {
5
by: Joakim Hove | last post by:
Hello, I have written a program in C; this programs uses an external proprietary library. When calling a certain function in the external library, the particular function writes a message to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.