Skip to content

Commit

Permalink
fix issue that print non-ascii character may cause exception (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
yushihang committed Jun 20, 2024
1 parent c6906d8 commit c751fe5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lldb/logs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import threading
import time
import os
import sys

def background_follow(filename):
with open(filename, 'r') as file:
with open(filename, 'r', encoding='utf-8') as file:
file.seek(0, os.SEEK_END)
utf8_stdout = open(sys.stdout.fileno(), mode='w', encoding='utf-8', closefd=False)

while True:
line = file.readline()

if not line:
time.sleep(0.1)
continue

print(line.rstrip("\n"), end=None)
try:
line = file.readline()

if not line:
time.sleep(0.1)
continue

print(line.rstrip("\n"), end=None, file=utf8_stdout, flush=True)

except UnicodeDecodeError as e:
print(f"UnicodeDecodeError occurred while following file {filename}: {e}")


def follow(debugger, command, result, internal_dict):
Expand Down

0 comments on commit c751fe5

Please sign in to comment.