Queue.join() blocks 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),可以使用queue.SimpleQueue而不是queue.Queue作为更轻的版本SimpleQueue是线程安全的,而且更安全,如answered here
It handles reentrancy - it is safe to call queue.SimpleQueue.put in precarious situations where it might be interrupting other work in the same thread. For example, you can safely call it from __del__ methods, weakref callbacks, or signal module signal handlers.
Queue.join()
函数,否则不必调用task_done()
李>task_done
,join
),可以使用queue.SimpleQueue
而不是queue.Queue
作为更轻的版本SimpleQueue
是线程安全的,而且更安全,如answered here注:至少这适用于其С实施
queue.Queue
使用int
作为put
的计数器。我的拙见是,这个计数器可能会占用太多的内存,这更多的是理论上的,而不是实践上的李>相关问题 更多 >
编程相关推荐