Skip to content

Commit

Permalink
./run_demo performance -c 1 --mediation --timing --trace-log
Browse files Browse the repository at this point in the history
Bug with prompt_toolkit and trace logging. Could only bump up the prompt_toolkit library so much since demos run on Python 3.6. However, I did attempt on 3.9 with the latest version of prompt_toolkit and setting an env var (see prompt-toolkit/python-prompt-toolkit#898). This still did not correct the issue, so reverted to existing code and just handled the exception(s). The output of the trace log is being written to the console, my limited understanding of this would be that the trace log works, but also triggers the prompt_toolkit to do the same work and gets into conflict.

Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed May 26, 2023
1 parent a848bcb commit 649779e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,18 @@ def handle_output(self, *output, source: str = None, **kwargs):
color = self.color or "fg:ansiblue"
else:
color = None
log_msg(*output, color=color, prefix=self.prefix_str, end=end, **kwargs)
try:
log_msg(*output, color=color, prefix=self.prefix_str, end=end, **kwargs)
except AssertionError as e:
if self.trace_enabled and self.trace_target == "log":
# when tracing to a log file,
# we hit an issue with the underlying prompt_toolkit.
# it attempts to output what is written by the log and can't find the
# correct terminal and throws an error. The trace log record does show
# in the terminal, so let's just ignore this error.
pass
else:
raise e

def log(self, *msg, **kwargs):
self.handle_output(*msg, **kwargs)
Expand Down
7 changes: 6 additions & 1 deletion demo/runners/support/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ def output_reader(handle, callback, *args, **kwargs):
for line in iter(handle.readline, b""):
if not line:
break
run_in_terminal(functools.partial(callback, line, *args))
try:
run_in_terminal(functools.partial(callback, line, *args))
except AssertionError as e:
# see comment in DemoAgent.handle_output
# trace log and prompt_toolkit do not get along...
pass


def log_msg(*msg, color="fg:ansimagenta", **kwargs):
Expand Down

0 comments on commit 649779e

Please sign in to comment.