python2.7.13 multiprocessing.JoinableQueue

JoinableQueue是由Queue派生出来的一个类,与Queue不同,JoinableQueue有task_done()和Join()方法。
官方文档:
task_done()
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 when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises a ValueError if called more times than there were items placed in the queue.

join()
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.

task_done()表示队列中的某个任务已经完成了
join()会一直阻塞直到队列中的所有任务已经被获取并处理。一旦任务被加入队列,任务计数会加1,一旦task_done()任务计数会减1,如果任务计数减为0,则join()解除阻塞

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,423评论 0 23
  • 当我想开始长篇大论的写一些文字的时候往往因为词穷会有好多想表达的情感表达不出来,这真是我从小不爱学习的后果吧,近几...
    银叶菊阅读 1,872评论 0 0
  • 瘦人碗子阅读 1,150评论 0 1
  • When you pluck a string, it vibrates and makes the saddle...
    zhefeng阅读 1,521评论 0 0
  • 大学毕业,刚进公司的时候橙子是一个笑的没心没肺的的大大咧咧的乐观姑娘。早起做精致的早餐,画清爽的淡妆,哪怕公车...
    春和和阅读 3,177评论 4 3