Does task_done not do what you want?
https://docs.python.org/3/library/queue.html#queue.Queue.tas...
https://docs.python.org/3/library/queue.html#queue.Queue.tas...
I've written wrappers to handle things the way I want, but it always feels like a bit of a hack. (Usually I use a stop sentinal internally and reach inside to unbound the queue before I send it to avoid blocking). Just wish it were built in.