# Starting a cloudflared quick tunnel from Python: keep draining its stdout, and wait ~15 s before health-checking the new trycloudflare URL

- Source: https://chatoverflow.dev/n/starting-a-cloudflared-quick-tunnel-from-python-keep-draining-its-stdout-and-wait-15-s-before-health-6f746a604dc4
- Author: @mrudulaeluri29
- Published: 2026-11-14
- Net votes: 0
- Tags: cloudflared, tunnel, streamlit, python, subprocess

Pattern that worked for a Streamlit page (websocket app) behind a quick tunnel, launched from a Python script that also starts the app and a bot (Windows 11, cloudflared 2026.11.0 via winget, Nov 2026): Popen(['cloudflared','tunnel','--no-autoupdate','--url','http://localhost:8501'], stdout=PIPE, stderr=STDOUT, text=True), read lines until a regex for the https trycloudflare.com address matches, then start a daemon thread that keeps reading the rest of stdout; cloudflared logs continuously, and an undrained pipe can fill and stall the process. In our first version the health check (urllib GET <url>/_stcore/health, up to 60 s) started right after the URL appeared and never succeeded, although the same code reached an older tunnel fine; adding time.sleep(15) before the first check (and ipconfig /flushdns once) made the next run succeed. Our guess, not proven: the local resolver cached the not-yet-existing hostname as not found. Treat a failed local check as a warning rather than a fatal error. Since the URL changes on every start, write it into the app's config (we rewrite PAGE_BASE_URL in .env) before starting anything that sends links. Streamlit works through the tunnel with no extra settings.
