Example #1
0
async def subprocess_based_service(cmd: List[str], service_url: str,
                                   log_file: TextIO) -> WebDriver:
    closers = []
    try:
        impl = get_subprocess_impl()
        process = await impl.start_process(cmd, log_file)
        closers.append(partial(impl.stop_process, process))
        session = ClientSession()
        closers.append(session.close)
        count = 0
        while True:
            try:
                if await tasked(check_service_status(session, service_url)):
                    break
            except:
                # TODO: make this better
                count += 1
                if count > 30:
                    raise Exception("not starting?")
                await asyncio.sleep(0.5)
        return WebDriver(Connection(session, service_url), closers)
    except:
        for closer in reversed(closers):
            await closer()
        raise
Example #2
0
 async def _check_version(self):
     if self.version_check:
         impl = get_subprocess_impl()
         output = await impl.run_process([self.binary, "--version"])
         match = self._version_re.search(output)
         if not match:
             raise ValueError(
                 "Could not determine version of geckodriver. To "
                 "disable version checking, set `version_check` to "
                 "`False`.")
         version_str = match.group(1)
         version = StrictVersion(version_str)
         if version < StrictVersion("0.16.1"):
             raise ValueError(
                 f"Geckodriver version {version_str} is too old. 0.16.1 or "
                 f"higher is required. To disable version checking, set "
                 f"`version_check` to `False`.")
Example #3
0
async def subprocess_based_service(
    cmd: List[str],
    service_url: str,
    log_file: TextIO,
    start_timeout: float = 15,
) -> WebDriver:
    closers = []
    try:
        impl = get_subprocess_impl()
        process = await impl.start_process(cmd, log_file)
        closers.append(partial(impl.stop_process, process))
        session = ClientSession()
        closers.append(session.close)
        count = 0

        async def wait_service():
            # Wait for service with exponential back-off
            for i in range(-10, 9999):
                try:
                    ok = await tasked(
                        check_service_status(session, service_url))
                except aiohttp.client_exceptions.ClientConnectorError:
                    # We possibly checked too quickly
                    ok = False
                if ok:
                    return
                await asyncio.sleep(start_timeout * 2**i)

        try:
            await asyncio.wait_for(wait_service(), timeout=start_timeout)
        except asyncio.TimeoutError:
            raise ArsenicError("not starting?")
        return WebDriver(Connection(session, service_url), closers)
    except:
        for closer in reversed(closers):
            await closer()
        raise