mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
Merge pull request #165 from orchardup/number-one
Stop 'fig up' when a container exits
This commit is contained in:
commit
23a8938809
@ -4,7 +4,7 @@ import sys
|
|||||||
|
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from .multiplexer import Multiplexer
|
from .multiplexer import Multiplexer, STOP
|
||||||
from . import colors
|
from . import colors
|
||||||
from .utils import split_buffer
|
from .utils import split_buffer
|
||||||
|
|
||||||
@ -34,7 +34,13 @@ class LogPrinter(object):
|
|||||||
prefix = color_fn(container.name + " | ")
|
prefix = color_fn(container.name + " | ")
|
||||||
# Attach to container before log printer starts running
|
# Attach to container before log printer starts running
|
||||||
line_generator = split_buffer(self._attach(container), '\n')
|
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):
|
def _attach(self, container):
|
||||||
params = {
|
params = {
|
||||||
|
@ -7,6 +7,11 @@ except ImportError:
|
|||||||
from queue import Queue, Empty # Python 3.x
|
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):
|
class Multiplexer(object):
|
||||||
def __init__(self, generators):
|
def __init__(self, generators):
|
||||||
self.generators = generators
|
self.generators = generators
|
||||||
@ -17,7 +22,11 @@ class Multiplexer(object):
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
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:
|
except Empty:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user