我有一个Python GUI应用程序。我有一个方法,每秒生成一个随机数(我称它为queueMsg)。如果queueMsg值是一个特定值(例如1),则存在另一个名为checkMsg的变量,在所有其他条件下,checkMsg = 0。 我正在另一种方法中使用此队列数据来将此值分配给2个变量并执行一些操作。如何将这些数据分配给变量。使用完后是否需要清除队列中的数据,否则新数据将清除队列中的旧数据?任何建议,请
def workerThread(self):
while self.running:
time.sleep(1)
queueMsg = random.randint(0,9)
checkMsg=0
if (queueMsg==1):
checkMsg= 1
self.queue.put(queueMsg,checkMsg) #is this right way to add data
def processData(self):
while self.queue.qsize():
try:
msg1 = self.queue.get(0)
msg2 = self.queue.get(1)
#this is not the right way to iterate q data?
# it also takes extra time to do it. this was freezing the program
print (msg1)
print (msg2)
# what i want is assign queue data to two variables msg1 and msg2
except queue.Empty:
pass