.. _using_procfiles: Using Procfiles =============== As described in :ref:`what_are_procfiles`, Procfiles are simple text files that describe the components required to run an application. This document describes some of the more advanced features of Honcho and the Procfile ecosystem. Syntax ------ The basic syntax of a Procfile is described in `the Heroku Procfile documentation `_. In summary, a Procfile is a plain text file placed at the root of your applications source tree that contains zero or more lines of the form:: : The ``process type`` is a string which may contain alphanumerics as well as underscores and dashes (``[A-Za-z0-9_-]+``), and uniquely identifies one type of process which can be run to form your application. For example: ``web``, ``worker``, or ``my_process_123``. ``command`` is a shell commandline which will be executed to spawn a process of the specified type. Environment files ----------------- You can also create a ``.env`` file alongside your Procfile which contains environment variables which will be available to all processes started by Honcho:: $ cat >.env <.env.one $ echo 'ANIMAL_2=elephant' >.env.two $ honcho -e .env.one,.env.two run sh -c 'env | grep -i animal' ANIMAL_1=giraffe ANIMAL_2=elephant Differences to Foreman ---------------------- While Honcho is based heavily on the Foreman_ project, it is not necessarily our intent to make Honcho feature-for-feature compatible with Foreman. There are some important differences between the two tools, some of which are simply the result of differences between Ruby and Python, and others are design choices. The following is a non-exhaustive list of these differences: .. _Foreman: https://github.com/ddollar/foreman No `honcho run {target}` '''''''''''''''''''''''' Foreman allows you to specify a Procfile target to both the `start` and `run` subcommands. To me, it seems obvious that this functionality belongs only in `honcho start`, a command that always reads the Procfile and has no other use for its ARGV, as opposed to `honcho run`, which is intended for running a shell command in the environment provided by Honcho and `.env` files. Because I don't have to guess at whether or not ARGV is a process name or a shell command, `honcho start` even supports multiple processes: `honcho start web worker`. Buffered output ''''''''''''''' By default, Python will buffer a program's output more aggressively than Ruby when a process has ``STDOUT`` connected to something other than a TTY. This can catch people out when running Python programs through Honcho: if the program only generates small amounts of output, it will be buffered, unavailable to Honcho, and will not display. One way around this is to set the ``PYTHONUNBUFFERED`` environment variable in your ``Procfile`` or your ``.env`` file. Be sure you understand the performance implications of unbuffered I/O if you do this. For example:: myprogram: PYTHONUNBUFFERED=true python myprogram.py