nickstenning / honcho

Honcho: a python clone of Foreman. For managing Procfile-based applications.
http://pypi.python.org/pypi/honcho
MIT License
1.59k stars 145 forks source link

Honcho buffers output to file #217

Closed MeabhG closed 4 years ago

MeabhG commented 4 years ago

When Honcho receives output from the processes it starts it buffers it before flushing to file. Adding self.output.flush() here (could be controlled by a config variable) would allow it to be line buffered. But there might be a better solution.

How to reproduce:

printing.py

import time
from datetime import datetime
import logging

logging.basicConfig(level=logging.INFO)

while 1:
    time.sleep(1)
    logging.info("Process printing.py output at: {}".format(datetime.now()))

run.sh

#!/usr/bin/env bash

pip install honcho
exec honcho start --procfile /etc/honcho/Procfile

Procfile

web0: python printing.py

Python no buffering docker run -d --rm --name honcho -v $(pwd)/printing.py:/printing.py --entrypoint /usr/local/bin/python docker-hub.ihs.demonware.net/python:3.7.5-stretch /printing.py and docker logs -f honcho in a second terminal to show line buffered logs

honcho buffering docker run -d --rm --name honcho -v $(pwd)/printing.py:/printing.py -v $(pwd)/run.sh:/run.sh -v $(pwd)/Procfile:/etc/honcho/Procfile --entrypoint bash docker-hub.ihs.demonware.net/python:3.7.5-stretch /run.sh and docker logs -f honcho in a second terminal to show honcho buffered logs (wait a few minutes for log dump)

Same behaviour with docker-hub.ihs.demonware.net/python:2.7.16-stretch

nickstenning commented 4 years ago

This has been a constant bugbear of mine. Python's default behaviour is to buffer writes to STDOUT when STDOUT is not a TTY.

I've changed Honcho's behaviour in d12e85f to always line-buffer output.

MeabhG commented 4 years ago

Thanks @nickstenning When do you think you'll be releasing a version that includes this change?