INNER CODE UNIT · Python

wait_for_file

defiprime/defiprime1 · scripts/product_add.py:87

def wait_for_file(raw, process, timeout=CAPTURE_TIMEOUT):
    deadline = time.monotonic() + timeout
    last_size = -1
    while time.monotonic() < deadline:
        if raw.exists() and raw.stat().st_size > 0 and raw.stat().st_size == last_size:
            break
        last_size = raw.stat().st_size if raw.exists() else -1
        if process.poll() is not None and raw.exists():
            break
        time.sleep(1)
    process.kill()
    process.wait()
    if not raw.exists() or raw.stat().st_size == 0:
        raise RuntimeError(f"no screenshot produced within {timeout}s")


def capture_screenshot(url, path):
    with tempfile.TemporaryDirectory() as profile:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…