Freddy Freddy - 7 months ago 30
Python Question

Daemontools shell script log to multilog

I have the following shell script:

exec 2>&1
echo "Starting ..."
python /home/services/

The python script consists just of a print command. The above script is a daemontools daemon and also a simple log mechanism is enabled (
). However, in the
I see the line "Starting ..." but not the printed commands from the python script.

Am I doing something wrong with the call or did I forget something?

The python script I am trying to run is:

from time import sleep
import sys

sys.stdout.write("Hello World")
print "Hello World"

while 1:
sys.stdout.write("Hello world")


Repeatedly running

sys.stdout.write("Hello world")

...just creates a single huge line of the form Hello worldHello worldHello world, with no guarantee that it ever flushes.

Put newlines on any content you write that doesn't have them implicitly (as through print), and flush your buffers when directly using sys.stdout.write():

while 1:
    sys.stdout.write("Hello world\n")  # add a newline
    sys.stdout.flush()                 # flush the buffer