Skip to content

Commit 5392398

Browse files
committed
Add test and docs for %(numprocs)d expansion. Closes Supervisor#1269
1 parent 5ec8d53 commit 5392398

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
suppresses the main log from being echoed to ``stdout`` as it normally
66
would. Patch by Trevor Foster.
77

8+
- Parsing ``command=`` now supports a new expansion, ``%(numprocs)d``, that
9+
expands to the value of ``numprocs=`` in the same section. Patch by
10+
Santjago Corkez.
11+
812
- Web UI buttons no longer use background images. Patch by Dmytro Karpovych.
913

1014
- The HTTP server will now send an ``X-Accel-Buffering: no`` header in

docs/configuration.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,11 @@ where specified.
640640
e.g. ``/path/to/programname --port=80%(process_num)02d`` might
641641
expand to ``/path/to/programname --port=8000`` at runtime. String
642642
expressions are evaluated against a dictionary containing the keys
643-
``group_name``, ``host_node_name``, ``process_num``, ``program_name``,
644-
``here`` (the directory of the supervisord config file), and all
645-
supervisord's environment variables prefixed with ``ENV_``. Controlled
646-
programs should themselves not be daemons, as supervisord assumes it is
647-
responsible for daemonizing its subprocesses (see
643+
``group_name``, ``host_node_name``, ``program_name``, ``process_num``,
644+
``numprocs``, ``here`` (the directory of the supervisord config file),
645+
and all supervisord's environment variables prefixed with ``ENV_``.
646+
Controlled programs should themselves not be daemons, as supervisord
647+
assumes it is responsible for daemonizing its subprocesses (see
648648
:ref:`nondaemonizing_of_subprocesses`).
649649

650650
.. note::
@@ -661,6 +661,8 @@ where specified.
661661

662662
*Introduced*: 3.0
663663

664+
*Changed*: 4.2.0. Added support for the ``numprocs`` expansion.
665+
664666
``process_name``
665667

666668
A Python string expression that is used to compose the supervisor

supervisor/tests/test_options.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,12 +1674,12 @@ def test_processes_from_section_process_num_expansion(self):
16741674
instance = self._makeOne()
16751675
text = lstrip("""\
16761676
[program:foo]
1677+
process_name = foo_%(process_num)d
16771678
command = /bin/foo --num=%(process_num)d
16781679
directory = /tmp/foo_%(process_num)d
16791680
stderr_logfile = /tmp/foo_%(process_num)d_stderr
16801681
stdout_logfile = /tmp/foo_%(process_num)d_stdout
16811682
environment = NUM=%(process_num)d
1682-
process_name = foo_%(process_num)d
16831683
numprocs = 2
16841684
""")
16851685
from supervisor.options import UnhosedConfigParser
@@ -1697,6 +1697,23 @@ def test_processes_from_section_process_num_expansion(self):
16971697
'/tmp/foo_%d_stdout' % num)
16981698
self.assertEqual(pconfigs[num].environment, {'NUM': '%d' % num})
16991699

1700+
def test_processes_from_section_numprocs_expansion(self):
1701+
instance = self._makeOne()
1702+
text = lstrip("""\
1703+
[program:foo]
1704+
process_name = foo_%(process_num)d
1705+
command = /bin/foo --numprocs=%(numprocs)d
1706+
numprocs = 2
1707+
""")
1708+
from supervisor.options import UnhosedConfigParser
1709+
config = UnhosedConfigParser()
1710+
config.read_string(text)
1711+
pconfigs = instance.processes_from_section(config, 'program:foo', 'bar')
1712+
self.assertEqual(len(pconfigs), 2)
1713+
for num in (0, 1):
1714+
self.assertEqual(pconfigs[num].name, 'foo_%d' % num)
1715+
self.assertEqual(pconfigs[num].command, "/bin/foo --numprocs=%d" % 2)
1716+
17001717
def test_processes_from_section_expands_directory(self):
17011718
instance = self._makeOne()
17021719
text = lstrip("""\

0 commit comments

Comments
 (0)