From d6d5d4263a3986f47c814cf0152f935b9ac9d9d3 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Thu, 1 Dec 2016 14:47:24 -0500 Subject: [PATCH] Only run ssh control persist cleanup from main process, flush after writing end marker for job event data. --- awx/lib/tower_display_callback/cleanup.py | 5 +++++ awx/lib/tower_display_callback/events.py | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/awx/lib/tower_display_callback/cleanup.py b/awx/lib/tower_display_callback/cleanup.py index 7a0387cddf..ad99fb20bb 100644 --- a/awx/lib/tower_display_callback/cleanup.py +++ b/awx/lib/tower_display_callback/cleanup.py @@ -28,9 +28,14 @@ import psutil __all__ = [] +main_pid = os.getpid() + @atexit.register def terminate_ssh_control_masters(): + # Only run this cleanup from the main process. + if os.getpid() != main_pid: + return # Determine if control persist is being used and if any open sockets # exist after running the playbook. cp_path = os.environ.get('ANSIBLE_SSH_CONTROL_PATH', '') diff --git a/awx/lib/tower_display_callback/events.py b/awx/lib/tower_display_callback/events.py index f85da9c233..86fab2895b 100644 --- a/awx/lib/tower_display_callback/events.py +++ b/awx/lib/tower_display_callback/events.py @@ -123,7 +123,7 @@ class EventContext(object): def get_end_dict(self): return {} - def dump(self, fileobj, data, max_width=78): + def dump(self, fileobj, data, max_width=78, flush=False): b64data = base64.b64encode(json.dumps(data)) with self.display_lock: fileobj.write(u'\x1b[K') @@ -132,12 +132,14 @@ class EventContext(object): escaped_chunk = u'{}\x1b[{}D'.format(chunk, len(chunk)) fileobj.write(escaped_chunk) fileobj.write(u'\x1b[K') + if flush: + fileobj.flush() def dump_begin(self, fileobj): self.dump(fileobj, self.get_begin_dict()) def dump_end(self, fileobj): - self.dump(fileobj, self.get_end_dict()) + self.dump(fileobj, self.get_end_dict(), flush=True) event_context = EventContext()