如何在python中创建单个处理队列?
我开发了一个使用python下载歌曲的电报机器人。我的程序将输入作为来自用户的链接,并存储在队列中。我有一个函数,如果队列中有项目,则处理该队列,否则等待队列被填满。我的职能是如何在python中创建单个处理队列?,python,python-3.x,list,queue,python-telegram-bot,Python,Python 3.x,List,Queue,Python Telegram Bot,我开发了一个使用python下载歌曲的电报机器人。我的程序将输入作为来自用户的链接,并存储在队列中。我有一个函数,如果队列中有项目,则处理该队列,否则等待队列被填满。我的职能是 global my_queue my_queue =[] def process_queue(): if my_queue !=None: #download the songs from the queue and send it to the user else: #wait for the queu
global my_queue
my_queue =[]
def process_queue():
if my_queue !=None:
#download the songs from the queue and send it to the user
else:
#wait for the queue to be filled
@run_async
def get_input():
#get input from the user and append the queue list with the item
如果队列为空,如何使函数process_queue()单独工作并等待?我需要确保没有文件覆盖、竞争条件或死锁。一个真正的
队列。队列
、一个单独的线程和一个.get()
。有没有有效的方法?没有线程请解释线程之间的关系→ 效率不高!