mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-06-19 21:55:13 +00:00
Handle blocking io errors when writing all to an fd
This commit is contained in:
parent
18ed56b639
commit
e68debc94e
1 changed files with 7 additions and 2 deletions
|
|
@ -430,11 +430,16 @@ def parse_address_spec(spec: str) -> Tuple[AddressFamily, Union[Tuple[str, int],
|
|||
return family, address, socket_path
|
||||
|
||||
|
||||
def write_all(fd: int, data: Union[str, bytes]) -> None:
|
||||
def write_all(fd: int, data: Union[str, bytes], block_until_written: bool = True) -> None:
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
while data:
|
||||
n = os.write(fd, data)
|
||||
try:
|
||||
n = os.write(fd, data)
|
||||
except BlockingIOError:
|
||||
if not block_until_written:
|
||||
raise
|
||||
continue
|
||||
if not n:
|
||||
break
|
||||
data = data[n:]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue