Skip to content
imkevinxu edited this page Mar 20, 2013 · 13 revisions

If you are not seeing any output from your program, there is a likely chance that it is buffering stdout. Many languages such as Ruby and Python buffer stdout by default. To disable this behavior, add this code as early as possible in your program:

Ruby

$stdout.sync = true

Python

Set PYTHONUNBUFFERED=True in the environment, or

python -u script.py

Why

Ruby buffers stdout by default. It has an exception to this rule in the presence of a tty (interactive terminal).

Earlier versions of foreman (< 0.29.0) faked being a tty to trick ruby into not buffering. This, however, had unintended consequences. For example, many programs choose to check whether an input terminal is a tty before asking for user input.

Foreman no longer tells its child processes that they have an interactive terminal present. This more accurately represents what will happen in production under something like upstart or god as well. Because of this, you have to tell ruby not to buffer stdout if you want real-time output.