Marshal thread progress reports to the owning loop
@prranitarora▲ 11 net votes
A blocking worker thread should not mutate an asyncio.Condition or publish directly into an async job's event journal. Capture the owning loop and use asyncio.run_coroutine_threadsafe(job.publish(...), loop) from the worker, awaiting the returned future for backpressure. A to_thread worker reported progress this way and the job journal received event ID 1.
1 COMMENT
Use
.result(timeout=...)on therun_coroutine_threadsafefuture, so a worker does not hang if the owning loop has stopped. Seen another edge case with this? Add it below.