mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
async timeouts
This commit is contained in:
parent
20c88b2170
commit
9f1182dd1b
@ -123,8 +123,8 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
(reader, writer) = await self.__ensure_device()
|
(reader, writer) = await self.__ensure_device()
|
||||||
try:
|
try:
|
||||||
writer.write(b"\xAA\xBB\x03%s\xEE" % (cmd))
|
writer.write(b"\xAA\xBB\x03%s\xEE" % (cmd))
|
||||||
await writer.drain()
|
await asyncio.wait_for(writer.drain(), timeout=self.__timeout)
|
||||||
return (await reader.readexactly(6))[4]
|
return (await asyncio.wait_for(reader.readexactly(6), timeout=self.__timeout))[4]
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
get_logger(0).error("Can't send command to Tesmart KVM [%s]:%d: %s",
|
get_logger(0).error("Can't send command to Tesmart KVM [%s]:%d: %s",
|
||||||
self.__host, self.__port, tools.efmt(err))
|
self.__host, self.__port, tools.efmt(err))
|
||||||
@ -134,10 +134,10 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
async def __ensure_device(self) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]:
|
async def __ensure_device(self) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]:
|
||||||
if self.__reader is None or self.__writer is None:
|
if self.__reader is None or self.__writer is None:
|
||||||
try:
|
try:
|
||||||
(reader, writer) = await asyncio.open_connection(self.__host, self.__port)
|
(reader, writer) = await asyncio.wait_for(
|
||||||
sock = writer.get_extra_info("socket")
|
asyncio.open_connection(self.__host, self.__port),
|
||||||
# sock.settimeout(self.__timeout)
|
timeout=self.__timeout,
|
||||||
sock.settimeout(0)
|
)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
get_logger(0).error("Can't connect to Tesmart KVM [%s]:%d: %s",
|
get_logger(0).error("Can't connect to Tesmart KVM [%s]:%d: %s",
|
||||||
self.__host, self.__port, tools.efmt(err))
|
self.__host, self.__port, tools.efmt(err))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user