gevent.joinall()开启协程

相比于 AttributeError: module ‘select’ has no attribute ‘error’解决方法 这篇文章,这里我加了一句print("End of File")

这样之后输出就是成了下面这样子

GET: https://www.python.org/
GET: https://www.yahoo.com/
GET: https://github.com/
51558 bytes received from https://github.com/.
48866 bytes received from https://www.python.org/.
507204 bytes received from https://www.yahoo.com/.
End of File

可以看出: 在文章末尾,调用完所有的join的协程之后,才会到下面的过程。也就是平时所说的,阻塞住了~

from gevent import monkey

monkey.patch_all(select=False)
import requests
import gevent


def f(url):
    print('GET: %s' % url)
    data = requests.get(url).text
    print('%d bytes received from %s.' % (len(data), url))


gevent.joinall([
    gevent.spawn(f, 'https://www.python.org/'),
    gevent.spawn(f, 'https://www.yahoo.com/'),
    gevent.spawn(f, 'https://github.com/'),
])
print("End of File")
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肥宅_Sean

公众号“肥宅Sean”欢迎关注

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值