mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 15:04:50 +02:00
Handle blocking io errors when writing all to an fd
This commit is contained in:
@@ -430,11 +430,16 @@ def parse_address_spec(spec: str) -> Tuple[AddressFamily, Union[Tuple[str, int],
|
|||||||
return family, address, socket_path
|
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):
|
if isinstance(data, str):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
while data:
|
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:
|
if not n:
|
||||||
break
|
break
|
||||||
data = data[n:]
|
data = data[n:]
|
||||||
|
|||||||
Reference in New Issue
Block a user