简体   繁体   中英

Python Queue get()/task_done() issue

My consumer side of the queue:

m = queue.get()
queue.task_done()

<rest of the program>

Questions:

  1. Does task_done() effectively pops m off the queue and release whatever locks the consumer has on the queue?

  2. I need to use m during the rest of the program. Is it safe, or do I need to copy it before I call task_done() or is m usable after task_done() ?

be happy

No, queue.get() pops the item off the queue. After you do that, you can do whatever you want with it, as long as the producer works like it should and doesn't touch it anymore. queue.task_done() is called only to notify the queue that you are done with something (it doesn't even know about the specific item, it just counts unfinished items in the queue), so that queue.join() knows the work is finished.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM