From 055a7a1695bcf4b3a53e704936d8d1836dd481d2 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Fri, 4 Jan 2019 17:47:34 -0800 Subject: [PATCH] Fix IPC timeout incoherence Make IPCClient's timeout parameter be consistently seconds, rather than seconds on unix and milliseconds on windows. --- mypy/ipc.py | 4 ++-- mypy/test/testipc.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy/ipc.py b/mypy/ipc.py index 2d0139aca6cd..881b5c3f5592 100644 --- a/mypy/ipc.py +++ b/mypy/ipc.py @@ -94,10 +94,10 @@ def close(self) -> None: class IPCClient(IPCBase): """The client side of an IPC connection.""" - def __init__(self, name: str, timeout: Optional[int]) -> None: + def __init__(self, name: str, timeout: Optional[float]) -> None: super().__init__(name) if sys.platform == 'win32': - timeout = timeout or 0xFFFFFFFF # NMPWAIT_WAIT_FOREVER + timeout = int(timeout * 1000) if timeout else 0xFFFFFFFF # NMPWAIT_WAIT_FOREVER try: _winapi.WaitNamedPipe(self.name, timeout) except FileNotFoundError: diff --git a/mypy/test/testipc.py b/mypy/test/testipc.py index fed0d7fb41b1..f2ee77d5ff0f 100644 --- a/mypy/test/testipc.py +++ b/mypy/test/testipc.py @@ -28,7 +28,7 @@ def test_transaction_large(self) -> None: p = Process(target=server, args=(msg, queue), daemon=True) p.start() connection_name = queue.get() - with IPCClient(connection_name, timeout=1000) as client: + with IPCClient(connection_name, timeout=1) as client: assert client.read() == msg.encode() client.write(b'test') queue.close() @@ -41,11 +41,11 @@ def test_connect_twice(self) -> None: p = Process(target=server, args=(msg, queue), daemon=True) p.start() connection_name = queue.get() - with IPCClient(connection_name, timeout=1000) as client: + with IPCClient(connection_name, timeout=1) as client: assert client.read() == msg.encode() client.write(b'') # don't let the server hang up yet, we want to connect again. - with IPCClient(connection_name, timeout=1000) as client: + with IPCClient(connection_name, timeout=1) as client: assert client.read() == msg.encode() client.write(b'test') queue.close()