Skip to content

Commit

Permalink
Resolve race condition
Browse files Browse the repository at this point in the history
Sometimes, some messages were being executed at the same time, meaning
that the status wasn't being overwritten, it was displaying on a
separate line for both doing and done messages.

Rather than trying to have both sets of statuses being written out
concurrently, we write out all of the doing messages first. Then
the done messages are written out/updated, as they are completed.

Signed-off-by: Mazz Mosley <[email protected]>
  • Loading branch information
mnowster committed Jul 20, 2015
1 parent da6cbd4 commit 61787fe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def parallel_execute(command, containers, doing_msg, done_msg, **options):
stream = codecs.getwriter('utf-8')(sys.stdout)
lines = []

def container_command_execute(container, command, **options):
for container in containers:
write_out_msg(stream, lines, container.name, doing_msg)

def container_command_execute(container, command, **options):
return getattr(container, command)(**options)

with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
Expand All @@ -41,6 +43,10 @@ def container_command_execute(container, command, **options):


def write_out_msg(stream, lines, container_name, msg):
"""
Using special ANSI code characters we can write out the msg over the top of
a previous status message, if it exists.
"""
if container_name in lines:
position = lines.index(container_name)
diff = len(lines) - position
Expand All @@ -56,6 +62,8 @@ def write_out_msg(stream, lines, container_name, msg):
lines.append(container_name)
stream.write("{}: {}... \r\n".format(container_name, msg))

stream.flush()


def json_hash(obj):
dump = json.dumps(obj, sort_keys=True, separators=(',', ':'))
Expand Down

0 comments on commit 61787fe

Please sign in to comment.