I'm not expert about python, could someone explain where is the problem?
I'd like to collect the stdout through supervisor http://supervisord.org/
I've made 3 different scripts that print output, for bash and PHP I can collect the output, without problems, python doesn't work.
php_test.sh
#!/usr/bin/php
<?php
for($i=0;$i<100000;$i++){
sleep(5);
echo 'test';
}
?>
bash_test.sh
#!/bin/bash
for i in `seq 1 100000`; do
sleep 5
echo item: $i
done
python_test.sh ( with differents tests to print output )
#!/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")
My supervisor config files
bash
[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
php
[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
python
[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
Thank so much for the help. It's driving me crazy ;[
Python output is buffered, use this after print
sys.stdout.flush()
or (Python 3)
print(something, flush=True)
or better
import logging
logging.warning('Watch out!')
https://docs.python.org/3/howto/logging.html
You can also install a stdout friendly version using pip install supervisor-stdout
. Find the usage instructions here.
UPDATE:
you can also update your supervisord.conf
to point the output to stdout.
[program:worker2]
command=bash yourscript.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With