我怀疑这与b/w{await
。
然而,;除了新对象被指定为async_generator
之外,我还不清楚它与coroutine
之间的区别。
(除了我在标题中提出的问题外,我不知道还有什么其他问题可以问…)
import asyncio
async def async_generator_spits_out_letters():
yield 'a'
yield 'b'
yield 'c'
yield 'd'
await asyncio.sleep(0)
async def coroutine_prints_messages():
while True:
print('hi')
await asyncio.sleep(2)
def test_it():
print(type(async_generator_spits_out_letters))
print(type(coroutine_prints_messages))
# This is how I choose to do newlines....it's easier for me to read. :[
print(); print()
print(type(async_generator_spits_out_letters()))
print(type(coroutine_prints_messages()))
这使得:
<class 'async_generator'>
<class 'coroutine'>
<class 'function'>
<class 'function'>
我对这件事一无所知
为了使一个
这是为了防止async_generator
产生函数在eventloop中运行,它的输出必须包装在一个coroutine.
async_generator
直接在事件循环中产生值。循环仅类似于任务&;未来
如果循环从其任务之一接收到整数或字符串或..任何不是从
future
派生的内容,它将中断因此
coroutines
必须:future
s(或future
的子类)这里是main()
以下是输出:
相关问题 更多 >
编程相关推荐