Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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_Python 3.x_List_Queue_Python Telegram Bot - Fatal编程技术网

如何在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

我开发了一个使用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()单独工作并等待?我需要确保没有文件覆盖、竞争条件或死锁。

一个真正的
队列。队列
、一个单独的线程和一个
.get()
。有没有有效的方法?没有线程请解释线程之间的关系→ 效率不高!