当前位置: 首页 > 图灵资讯 > 行业资讯> python gevent的原理分析

python gevent的原理分析

发布时间:2024-08-04 17:32:07

原理

1、遇到IO操作的grenlet(Inputenlet)、当output输入输出,如网络、文件操作等。),如果访问网络,将自动切换到其他grenlet。2、IO操作完成后,在适当的时候切换并继续执行。

实例

importgevent


deffun(n):
foriinrange(n):
print(gevent.getcurrent(),i)


g1=gevent.spawn(fun,5)
g2=gevent.spawn(fun,5)
g3=gevent.spawn(fun,5)

g1.join()
g2.join()
g3.join()

以上是python Gevent的原理分析,希望对大家有所帮助。学习更多的编程基础知识:python学习网

本教程的操作环境:windows7系统,Python 3.9.1,DELL G3电脑。

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12