Python 多线程进程高级指南(二)

• 多进程，多线程（并行）
• 协程 （并发）

[En]

This article is not complete, but it brings together a lot of content that the author thinks is very essential, so it can be regarded as a summary article.

多线程和多进程

• Python在IO操作时，会自动释放GIL，因此IO密集型程序的多线程是有意义的
• 即使不能多线程，还能多进程，这才是核武器。而Python有非常好用的multiprocessing库解决进程间协同问题。

import os
from parallelize import parallelize

for i in parallelize(range(100)):
print(os.getpid(), i)


[En]

For most people, higher-order functions are inherently anti-human. It will be much more refreshing to write it down this way. It’s worth learning! When this part is finished, we enter the mysterious world of Xiecheng.

asyncio 和 yield from

yield是Python中的关键字。我们熟悉的是它的迭代生成器用法。更高阶的则是协程。例如：

a=yield b

def merge():
yield from 'ABC'
yield from '123'


Original: https://www.cnblogs.com/buptzym/p/6950172.html
Author: FerventDesert
Title: Python 多线程进程高级指南(二)

(0)