【发布时间】:2020-02-26 20:08:05
【问题描述】:
我想知道 python 中是否有类似queue 这样的并发结构,但能够删除特定元素。
例子:
import queue
#with queue would be
q = queue.Queue()
#put some element
q.put(elem)
#i want to delete a specific element
#but queue does not provide this method
q.remove(elem)
我可以用什么?
【问题讨论】:
-
只是一个
list...? -
首先解释一下为什么要使用队列?默认情况下,队列具有 FIFO 的性质,因此
list在这里可能是更好的选择 -
队列只是线程安全结构的一个例子,列表是线程安全的吗?
标签: python collections concurrency