Python - Supervisor how to log the standard output -
<p>I'm not expert about python, could someone explain where is the problem?</p>

<p>I'd like to collect the stdout through supervisor 
<a href="http://supervisord.org/" rel="nofollow">http://supervisord.org/</a></p>

<p>I've made 3 different scripts that print output, for bash and PHP I can collect the output, without problems, python doesn't work.</p>

<p>php_test.sh</p>

<pre><code>#!/usr/bin/php
&lt;?php
    for($i=0;$i&lt;100000;$i++){
        sleep(5);
        echo 'test';
    }
?&gt;
</code></pre>

<p>bash_test.sh</p>

<pre><code>#!/bin/bash
for i in `seq 1 100000`; do
    sleep 5
    echo item: $i
done
</code></pre>

<p>python_test.sh ( with differents tests to print output )</p>

<pre><code>#!/usr/bin/python3
import time
import sys
from contextlib import redirect_stdout

for num in range(0,100000):
    time.sleep(5)
    print("test!")
    sys.stdout.write("test")
    with redirect_stdout(sys.stderr):
        print("test")
</code></pre>

<p>My supervisor config files</p>

<p>bash</p>

<pre><code>[program:bash_test]
process_name=bash_test
command=/home/user/bash_test.sh
stdout_logfile=/home/user/bash_test_output.log
stdout_logfile_maxbytes=0
</code></pre>

<p>php</p>

<pre><code>[program:php_test]
process_name=php_test
command=/home/user/php_test.sh
stdout_logfile=/home/user/php_test_output.log
stdout_logfile_maxbytes=0
</code></pre>

<p>python</p>

<pre><code>[program:python_test]
process_name=python_test
command=/home/user/python_test.sh
stdout_logfile=/home/user/python_test_output.log
stdout_logfile_maxbytes=0
</code></pre>

<p>Thank so much for the help.
It's driving me crazy ;[</p>

<p>ok...python output is buffered
use after print</p>

<pre><code>sys.stdout.flush()
</code></pre>

<p>or ( python 3 )</p>

<pre><code>print(something, flush=True)
</code></pre>

<p>or more better </p>

<pre><code>import logging
logging.warning('Watch out!')
</code></pre>

<p><a href="https://docs.python.org/3/howto/logging.html" rel="nofollow">https://docs.python.org/3/howto/logging.html</a></p>

python linux python-3.x unix supervisord