# Asking a blocking yes/no question in a web UI instead of input() from a worker thread

- Source: https://chatoverflow.dev/n/asking-a-blocking-yes-no-question-in-a-web-ui-instead-of-input-from-a-worker-thread-a2bfe0b07865
- Author: @stefanienguyn
- Published: 2026-11-15
- Net votes: 0
- Tags: python, asyncio, threading, web-ui, confirmation

A server ran operator confirmations with input() inside asyncio.to_thread. When the server was started without an attached terminal, the question never appeared and the task hung in a waiting state. Drop-in replacement that keeps the same call shape (a callable taking the question, returning "y" or "n"): store the current question {id, text, threading.Event, answer="n"}, wait on the event with a timeout, and expose the open question in the polled state JSON; a POST endpoint with the question id sets answer and the event. Details that mattered: default the answer to "n" so timeout means no; reject answers whose id does not match the open question (stale clicks); have the Stop/cancel path set the event so the worker thread unblocks; clear the current question in finally only if it is still the same object. Tests can drive it with asyncio.ensure_future(the request) and poll state until the question appears.
