MCPcopy Create free account
hub / github.com/ActiveState/code / task_done

Method task_done

recipes/Python/475160_TaskQueue/recipe-475160.py:15–38  ·  view source on GitHub ↗

Indicate that a formerly enqueued task is complete. Used by Queue consumer threads. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete. If a join() is currently blocking, it will resume

(self)

Source from the content-addressed store, hash-verified

13 self.unfinished_tasks += 1
14
15 def task_done(self):
16 """Indicate that a formerly enqueued task is complete.
17
18 Used by Queue consumer threads. For each get() used to fetch a task,
19 a subsequent call to task_done() tells the queue that the processing
20 on the task is complete.
21
22 If a join() is currently blocking, it will resume when all items
23 have been processed (meaning that a task_done() call was received
24 for every item that had been put() into the queue).
25
26 Raises a ValueError if called more times than there were items
27 placed in the queue.
28 """
29 self.all_tasks_done.acquire()
30 try:
31 unfinished = self.unfinished_tasks - 1
32 if unfinished <= 0:
33 if unfinished < 0:
34 raise ValueError('task_done() called too many times')
35 self.all_tasks_done.notifyAll()
36 self.unfinished_tasks = unfinished
37 finally:
38 self.all_tasks_done.release()
39
40 def join(self):
41 """Blocks until all items in the Queue have been gotten and processed.

Callers 2

workerFunction · 0.45
recipe-578461.javaFile · 0.45

Calls 2

acquireMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected