複数のスレッドがリスト(これらは生産者である)に項目を追加することができますし、それは常に(リストの最後に、そう)のappend()コールを介して行われます:のみ
self.threadCallQueue.append((f, args, kw))
メインスレッドは、これまでのアイテムを読み込み、リストから削除(この1つは、消費者である)、それは常にリストの先頭に読み込む:だから
# Keep track of how many calls we actually make, as we're
# making them, in case another call is added to the queue
# while we're in this loop.
count = 0
total = len(self.threadCallQueue)
for (f, a, kw) in self.threadCallQueue:
try:
f(*a, **kw)
except:
log.err()
count += 1
if count == total:
break
del self.threadCallQueue[:count]
、一つのスレッドがリストや他人の先頭から読み込むので、最後に書いて、これは私ですPythonリストがである限り、スレッドセーフでです。これは、関数のソースコードに記載されています。
# lists are thread-safe in CPython, but not in Jython
# this is probably a bug in Jython, but until fixed this code
# won't work in Jython.
詳細な回答ありがとうございます。 – gmemon