Add lock to RawConnection

To avoid `self.writer.drain()` is called in parallel.
Reference: https://bugs.python.org/issue29930
This commit is contained in:
mhchia
2019-08-20 17:09:38 +08:00
parent 5768daa9bf
commit 0b466ddc86
5 changed files with 37 additions and 27 deletions

View File

@ -12,12 +12,12 @@ class RawConnectionCommunicator(IMultiselectCommunicator):
self.conn = conn
async def write(self, msg_str: str) -> None:
msg_bytes = encode_delim(msg_str)
self.conn.writer.write(msg_bytes)
await self.conn.writer.drain()
msg_bytes = encode_delim(msg_str.encode())
await self.conn.write(msg_bytes)
async def read(self) -> str:
return await read_delim(self.conn.reader)
data = await read_delim(self.conn.reader)
return data.decode()
class StreamCommunicator(IMultiselectCommunicator):
@ -27,8 +27,9 @@ class StreamCommunicator(IMultiselectCommunicator):
self.stream = stream
async def write(self, msg_str: str) -> None:
msg_bytes = encode_delim(msg_str)
msg_bytes = encode_delim(msg_str.encode())
await self.stream.write(msg_bytes)
async def read(self) -> str:
return await read_delim(self.stream)
data = await read_delim(self.stream)
return data.decode()