【发布时间】:2020-07-18 00:57:00
【问题描述】:
我正试图让我的不和谐机器人一次响应多个人。我的一个功能与 spacy 模块交互并处理大块文本。如果该函数被调用一次,它最终会冻结我的机器人,因为它正在尝试处理第一个请求。
nlp = spacy.load("en_core_web_sm")
@bot.event
async def on_message(message):
if message.content.startswith('!research'):
doc = 'long paragraphs...'
#Searches through doc for sentences relating to a word
nlp(doc) #Takes time to process here
results = textacy.extract.semistructured_statements(document, 'a word')
我的问题:如何同时运行具有多个请求的类似功能,或者我在这里做错了什么?
【问题讨论】:
-
你需要寻找支持异步编程的库。天真地说你可以通过使用
async和await关键字来识别它们。 -
如果不存在这样的库,那么你可以试试这个:stackoverflow.com/questions/53587063/…
标签: python discord discord.py spacy