What's the difference between heapq and PriorityQueue in python?

ساخت وبلاگ

Vote count: 0

In python there's a built-in heapq algorithm that gives you push, pop, nlargest, nsmallest... etc that you can apply to lists. However, there's also the queue.PriorityQueue class that seems to support more or less the same functionality. What's the difference, and when would you use one over the other?

asked 2 mins ago

1 Answer

Vote count: 0

Queue.PriorityQueue is a thread-safe class, while collections.heapq makes no thread-safety guarantees.

From the Queue module documentation:

The Queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics. It depends on the availability of thread support in Python; see the threading module.

answered 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 251 تاريخ : سه شنبه 14 ارديبهشت 1395 ساعت: 4:21