Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue that print non-ascii character may cause exception #22

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
yushihang marked this conversation as resolved.
Show resolved Hide resolved

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


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