Flush on each write; allow empty lines when parsing action

This commit is contained in:
Zanie 2024-01-16 11:46:52 -06:00
parent d1e39076bf
commit 0914965c37
1 changed files with 5 additions and 2 deletions

View File

@ -307,7 +307,10 @@ class Action(enum.Enum):
def parse_action(buffer: TextIO) -> Action: def parse_action(buffer: TextIO) -> Action:
action = buffer.readline().rstrip("\n") # Wait until we receive non-empty content
action = None
while not action:
action = buffer.readline().rstrip("\n")
return Action.from_str(action) return Action.from_str(action)
@ -428,7 +431,7 @@ def send_shutdown(file: TextIO):
def write_safe(file: TextIO, *args: str): def write_safe(file: TextIO, *args: str):
# Ensures thre are no newlines in the output # Ensures thre are no newlines in the output
args = [str(arg).replace("\n", "\\n") for arg in args] args = [str(arg).replace("\n", "\\n") for arg in args]
print(*args, file=file) print(*args, file=file, flush=True)
####################### #######################