<commit_before>import os
import asyncio
import logging
from multiprocessing import cpu_count
from typing import Dict

from websockets.exceptions import InvalidHandshake, ConnectionClosed

from .chromerdp import ChromeRemoteDebugger, Page, TemporaryBrowserFailure

logger = logging.getLogger(__name__)

PRERENDER_TIMEOUT: int = int(os.environ.get('PRERENDER_TIMEOUT', 30))
CONCURRENCY_PER_WORKER: int = int(os.environ.get('CONCURRENCY', cpu_count() * 2))
MAX_ITERATIONS: int = int(os.environ.get('ITERATIONS', 200))
CHROME_HOST: int = int(os.environ.get('CHROME_HOST', 'localhost'))
CHROME_PORT: int = int(os.environ.get('CHROME_PORT', 9222))


class Prerender:
    def __init__(self, host: str = CHROME_HOST, port: int = CHROME_PORT, loop=None):
        self.host = host
        self.port = port
        self.loop = loop
        self._rdp = ChromeRemoteDebugger(host, port, loop=loop)
        self._pages = set()
        self._idle_pages = asyncio.Queue(loop=self.loop)

    async def bootstrap(self) -> None:
        for i in range(CONCURRENCY_PER_WORKER):
            page = await self._rdp.new_page()
            await self._idle_pages.put(page)
            self._pages.add(page)

    async def pages(self) -> Dict:
        return await self._rdp.pages()

    async def version(self) -> Dict:
        return await self._rdp.version()

    async def shutdown(self) -> None:
        for page in self._pages:<commit_msg>CHROME_HOST should be str<commit_after>import os
import asyncio
import logging
from multiprocessing import cpu_count
from typing import Dict

from websockets.exceptions import InvalidHandshake, ConnectionClosed

from .chromerdp import ChromeRemoteDebugger, Page, TemporaryBrowserFailure

logger = logging.getLogger(__name__)

PRERENDER_TIMEOUT: int = int(os.environ.get('PRERENDER_TIMEOUT', 30))
CONCURRENCY_PER_WORKER: int = int(os.environ.get('CONCURRENCY', cpu_count() * 2))
MAX_ITERATIONS: int = int(os.environ.get('ITERATIONS', 200))
CHROME_HOST: str = os.environ.get('CHROME_HOST', 'localhost')
CHROME_PORT: int = int(os.environ.get('CHROME_PORT', 9222))


class Prerender:
    def __init__(self, host: str = CHROME_HOST, port: int = CHROME_PORT, loop=None):
        self.host = host
        self.port = port
        self.loop = loop
        self._rdp = ChromeRemoteDebugger(host, port, loop=loop)
        self._pages = set()
        self._idle_pages = asyncio.Queue(loop=self.loop)

    async def bootstrap(self) -> None:
        for i in range(CONCURRENCY_PER_WORKER):
            page = await self._rdp.new_page()
            await self._idle_pages.put(page)
            self._pages.add(page)

    async def pages(self) -> Dict:
        return await self._rdp.pages()

    async def version(self) -> Dict:
        return await self._rdp.version()

    async def shutdown(self) -> None:
        for page in self._pages:
{'fraction_non_alphanumeric': 0.10748155953635406, 'fraction_numerical': 0.007024938531787847, 'mean_word_length': 3.5641025641025643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1965436', 'n_tokens_mistral': 948, 'n_tokens_neox': 929, 'n_words': 220}