Handle blocking io errors when writing all to an fd
This commit is contained in:
parent
18ed56b639
commit
e68debc94e
@ -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:]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user