queue.Queue.join() usability: wait for current tasks only

I think it would be nice if queue.Queue.join() method supported a current_tasks: bool parameter: if True, join() waits only for the tasks which have already been put into the queue to be completed.

There are situations when the arrival of new tasks is unpredictable and therefore the current join() is unusable: join() may never return, although semantically I just want to wait for tasks that have already been enqueued (if any).

The code change required to implement this is trivial: maintain two fields added_tasks and done_tasks instead of a single unfinished_tasks, and then:

    def join(self, current_tasks: bool) -> None:
        with self.tasks_done_cond:
            if not current_tasks:
                # Wait until all tasks ever added are done
                while self.done_tasks < self.added_tasks:
                    self.tasks_done_cond.wait()
            else:
                # Wait only until tasks added *before* this join() call are done
                target_tasks = self.added_tasks
                while self.done_tasks < target_tasks:
                    self.tasks_done_cond.wait()

# tasks_done_cond is renamed all_tasks_done
# Also use tasks_done_cond.notify_all() in Queue.task_done().

Does calling Queue.shutdown work for your usecase? That would cause any further calls to put() to raise queue.Shutdown while letting the already-queued tasks finish.

No. I want all tasks submitted prior to a certain moment to complete, but not block nor permanently shutdown the submission of new tasks.