Python 我需要在eventloop中包含所有函数?
如果我有一个事件循环和异步函数:Python 我需要在eventloop中包含所有函数?,python,async-await,python-asyncio,Python,Async Await,Python Asyncio,如果我有一个事件循环和异步函数: # asyncio_coroutine_forever.py import asyncio async def hello_world(): print('Hello World') await good_evening() async def good_evening(): print('Good Evening') loop = asyncio.get_event_loop() try: loop.run_un
# asyncio_coroutine_forever.py
import asyncio
async def hello_world():
print('Hello World')
await good_evening()
async def good_evening():
print('Good Evening')
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(hello_world())
loop.run_forever()
finally:
print('closing event loop')
loop.close()
函数hellp_world由eventloop调用。第二个函数good_Night,是否在相同的eventloop中
我必须在循环中包含第二个函数还是只包含第一个函数?
如果我使用这个例子,第二个使用循环并切换上下文
run\u直到\u完成
将执行您的hello\u world
直到它返回或失败(它还会在过程中阻塞您的线程)run\u until\u complete
将运行一个future,直到它完成,但它也会导致事件循环运行,因此如果您计划一个future,它将在传递给run\u util\u complete
的函数之前运行