Skip to content

Commit

Permalink
Do not lock around writing to stdout, do not flush
Browse files Browse the repository at this point in the history
  • Loading branch information
sivel committed Jan 22, 2025
1 parent ca0df81 commit 0665c20
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/ansible_runner/display_callback/callback/awx_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# Python
import json
import stat
import multiprocessing
import threading
import base64
import functools
Expand Down Expand Up @@ -127,7 +126,6 @@ class EventContext:
'''

def __init__(self):
self.display_lock = multiprocessing.RLock()
self._global_ctx = {}
self._local = threading.local()
if os.getenv('AWX_ISOLATED_DATA_DIR'):
Expand Down Expand Up @@ -224,24 +222,21 @@ def get_end_dict(self):

def dump(self, fileobj, data, max_width=78, flush=False):
b64data = base64.b64encode(json.dumps(data).encode('utf-8')).decode()
with self.display_lock:
# pattern corresponding to OutputEventFilter expectation
fileobj.write('\x1b[K')
for offset in range(0, len(b64data), max_width):
chunk = b64data[offset:offset + max_width]
escaped_chunk = f'{chunk}\x1b[{len(chunk)}D'
fileobj.write(escaped_chunk)
fileobj.write('\x1b[K')
if flush:
fileobj.flush()
# pattern corresponding to OutputEventFilter expectation
fileobj.write('\x1b[K')
for offset in range(0, len(b64data), max_width):
chunk = b64data[offset:offset + max_width]
escaped_chunk = f'{chunk}\x1b[{len(chunk)}D'
fileobj.write(escaped_chunk)
fileobj.write('\x1b[K')

def dump_begin(self, fileobj):
begin_dict = self.get_begin_dict()
self.cache.set(f":1:ev-{begin_dict['uuid']}", begin_dict)
self.dump(fileobj, {'uuid': begin_dict['uuid']})

def dump_end(self, fileobj):
self.dump(fileobj, self.get_end_dict(), flush=True)
self.dump(fileobj, self.get_end_dict())


event_context = EventContext()
Expand Down

0 comments on commit 0665c20

Please sign in to comment.