asgiref
asgiref copied to clipboard
Migrate work for finished `CurrentThreadExecutor` to previous executor
A CurrentThreadExecutor may terminate with work still remaining in its queue, or new work may be submitted later. We previously discarded remaining work, leading to deadlocks, and raised an error on submitting late work. But if there’s another CurrentThreadExecutor for the same thread below us on the stack, we should instead migrate the extra work there to allow it to eventually run.
Doing this in a thread-safe way requires replacing the queue.Queue abstraction with collections.deque and threading.ConditionVariable (the same primitives used to implement queue.Queue).
- Fixes #491
- Fixes #492
- Replaces and closes #493