You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
res = yield from foo() 在 foo 是一个 corotinue 的 function(所以,其被调用时候产生 coroutine 对象)或者是简单的函数返回 Task 和 Future 对象。
注意 yield from 对应的 coroutine 不能是阻塞的,必须让每一个网络 IO 都是异步的。
这样控制流才能尽快的到 event_loop 中。
在 coroutine 中使用 yield from 需要注意的是
Every arrangement of coroutines chained with yield from must be ultimately
driven by a caller that is not a coroutine, which invokes next(…) or .send(…) on
the outermost delegating generator, explicitly or implicitly (e.g., in a for loop).
The innermost subgenerator in the chain must be a simple generator that uses just
yield—or an iterable object.
而在 asyncio 中。
The coroutine chains we write are always driven by passing our outermost dele‐
gating generator to an asyncio API call, such as loop.run_until_complete(…)
The coroutine chains we write always end by delegating with yield from to some
asyncio coroutine function or coroutine method . In other words, the innermost subgenerator will be a library function that does the actual I/O, not something we write.
#type/python #async #public
The text was updated successfully, but these errors were encountered:
参考资料
named tuple
FrenchDeck
魔法方法
数据结构
生成表达式
Text versus Bytes
character issues
Byte Essentials
序列类型
Python 内置了两种基本的二进制序列类型:不可变的
bytes
和可变的bytearray
返回:
基本的解码
能用
chardet
检测字符所使用的编码BOM:字节序标记 (byte-order mark):
\ufffe
为字节序标记,放在文件开头,UTF-16 用它来表示文本以大端表示 (\xfe\xff
) 还是小端表示 (\xff\xfe
)。UTF-8 编码并不需要 BOM,但是微软还是给它加了 BOM,非常烦人。
处理文本文件
Chardet
,而不是重新发明轮子。默认编码
Concurrent with futures
download with concurrent.futures
futures
使用多进程
体验 Exector.map
Thread versus coroutine
coroutine 版本
Yielding from futures, tasks and coroutines
在 coroutine 中使用 yield from 需要注意的是
driven by a caller that is not a coroutine, which invokes next(…) or .send(…) on
the outermost delegating generator, explicitly or implicitly (e.g., in a for loop).
yield—or an iterable object.
而在 asyncio 中。
gating generator to an asyncio API call, such as loop.run_until_complete(…)
asyncio coroutine function or coroutine method . In other words, the innermost subgenerator will be a library function that does the actual I/O, not something we write.
#type/python #async #public
The text was updated successfully, but these errors were encountered: