Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中是否有线程安全(如队列)集类型?_Python_Thread Safety_Set_Queue - Fatal编程技术网

Python中是否有线程安全(如队列)集类型?

Python中是否有线程安全(如队列)集类型?,python,thread-safety,set,queue,Python,Thread Safety,Set,Queue,我在程序中使用了Queue.Queue,但如果有类似set的类型会更好。我需要的容器线程安全,但我不希望它被订购 def init_query_pool(self): self._pool = Queue.Queue() // todo: replace Queue.Queue with set self._new_query_pool() def _create_threads(self): sessions = session_util.load_sessions(

我在程序中使用了
Queue.Queue
,但如果有类似
set
的类型会更好。我需要的容器线程安全,但我不希望它被订购

def init_query_pool(self):
    self._pool = Queue.Queue() // todo: replace Queue.Queue with set
    self._new_query_pool()

def _create_threads(self):
    sessions = session_util.load_sessions()

    for s in sessions:
        t = threading.Thread(target=self.gen_qs, args=(s,))
        t.start()

def gen_qs(self, session):
    params = self._init_params(session)
    while True:
        qs = self._pool.get()
        self._search(session, params, qs)

我不确定我是否理解这个问题。您只需使用
set
,对吗?我真的看不出队列与集合是如何关联的,这似乎是不同的概念?我认为问题可能是“集合是线程安全的”吗?我的代码可能是@freakish,你能理解我吗?那么使用set避免重复的原因是什么呢?因为否则设置与队列相比效率很低。@奇怪,这不是主要原因,我只想无序