首页 > 解决方案 > 如何在python中创建一个单独的处理队列?

问题描述

我开发了一个使用 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 queue to be filled

@run_async
def get_input():
    #get input from the user and append the queue list with the item

如何使我的函数 process_queue() 单独工作并等待队列为空?我需要确保没有覆盖文件或竞争条件或死锁。

标签: pythonpython-3.xlistqueuepython-telegram-bot

解决方案


推荐阅读