Esempio n. 1
0
    def wait_connectable(timeout: Union[int, float]) -> None:
        end = time.monotonic() + timeout
        delay = CONNECT_PIPE_INIT_DELAY
        address = get_pipe_name()
        while time.monotonic() > end:
            try:
                handle = _overlapped.ConnectPipe(address)
                _winapi.CloseHandle(handle)
                return
            except OSError as exc:
                if exc.winerror != _overlapped.ERROR_PIPE_BUSY:
                    raise

            # ConnectPipe() failed with ERROR_PIPE_BUSY: retry later
            delay = min(delay * 2, CONNECT_PIPE_MAX_DELAY)
            time.sleep(delay)
        raise Exception("Server did not start")
Esempio n. 2
0
    async def connect_pipe(self, address):
        delay = CONNECT_PIPE_INIT_DELAY
        while True:
            # Unfortunately there is no way to do an overlapped connect to
            # a pipe.  Call CreateFile() in a loop until it doesn't fail with
            # ERROR_PIPE_BUSY.
            try:
                handle = _overlapped.ConnectPipe(address)
                break
            except OSError as exc:
                if exc.winerror != _overlapped.ERROR_PIPE_BUSY:
                    raise

            # ConnectPipe() failed with ERROR_PIPE_BUSY: retry later
            delay = min(delay * 2, CONNECT_PIPE_MAX_DELAY)
            await tasks.sleep(delay)

        return windows_utils.PipeHandle(handle)