【发布时间】:2019-05-18 14:18:54
【问题描述】:
在下面的代码中,我想调用 task1 和 task2 但不期待这些方法的返回,这可能吗?
import asyncio
async def say(something, delay):
await asyncio.sleep(delay)
print(something)
loop = asyncio.get_event_loop()
task1 = loop.create_task(say('hi', 1))
task2 = loop.create_task(say('hoi', 2))
loop.run_until_complete(asyncio.gather(task1, task2))
我想在一个while循环中处理一个队列中的一些东西,而不是等待,因为我不需要返回函数,例如伪代码:
import asyncio
async def say(something, delay):
await asyncio.sleep(delay)
print(something)
def main():
while True:
# search for database news
# call say asynchronous, but I do not need any return, I just want you to do anything, independent
time.sleep(1)
【问题讨论】:
标签: python-3.x asynchronous parallel-processing wait python-asyncio