Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions fig/cli/log_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from itertools import cycle

from .multiplexer import Multiplexer
from .multiplexer import Multiplexer, STOP
from . import colors
from .utils import split_buffer

Expand Down Expand Up @@ -34,7 +34,13 @@ def _make_log_generator(self, container, color_fn):
prefix = color_fn(container.name + " | ")
# Attach to container before log printer starts running
line_generator = split_buffer(self._attach(container), '\n')
return (prefix + line.decode('utf-8') for line in line_generator)

for line in line_generator:
yield prefix + line.decode('utf-8')

exit_code = container.wait()
yield color_fn("%s exited with code %s\n" % (container.name, exit_code))
yield STOP

def _attach(self, container):
params = {
Expand Down
11 changes: 10 additions & 1 deletion fig/cli/multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from queue import Queue, Empty # Python 3.x


# Yield STOP from an input generator to stop the
# top-level loop without processing any more input.
STOP = object()


class Multiplexer(object):
def __init__(self, generators):
self.generators = generators
Expand All @@ -17,7 +22,11 @@ def loop(self):

while True:
try:
yield self.queue.get(timeout=0.1)
item = self.queue.get(timeout=0.1)
if item is STOP:
break
else:
yield item
except Empty:
pass

Expand Down