Skip to content

Commit

Permalink
Enhance input handling in process wrapper to ensure newline terminati…
Browse files Browse the repository at this point in the history
…on and improve error handling
  • Loading branch information
polischuks committed Feb 15, 2025
1 parent 4d2469c commit f82e68f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions hstest/testing/process_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,21 @@ def is_finished(self, need_wait_output=True) -> bool:
return not self._alive

def provide_input(self, stdin: str) -> None:
if self._use_byte_stream:
stdin = stdin.encode()
self.process.stdin.write(stdin)
if not stdin.endswith('\n'):
stdin += '\n'
try:
if self._use_byte_stream:
stdin = stdin.encode('utf-8')
self.process.stdin.write(stdin)
self.process.stdin.flush()
else:
self.process.stdin.write(stdin)
self.process.stdin.flush()
except IOError as e:
# Handle pipe errors gracefully
if not self._alive:
return
raise e

def terminate(self) -> None:
OutputHandler.print("Terminate called")
Expand Down

0 comments on commit f82e68f

Please sign in to comment.