协程

作者: 裴general | 来源:发表于2018-08-12 23:32 被阅读0次

    [https://www.bilibili.com/read/cv846395 ]
    [https://www.cnblogs.com/zhangxinqi/p/8337207.html]

    
    def gevent_fun():
        from gevent import monkey
        monkey.patch_all(socket=True,select=True)
        from gevent.pool import Pool
        gevent_pool = Pool(800)
        urls = [urlx for i in range(1000000)]
        gevent_pool.map(fun, urls)
    

    ======================

    from gevent import monkey;
    
    monkey.patch_all()
    import gevent, requests
    
    def get_page(url):
        ret = requests.get(url).text
        print(ret)
    
    
    # g1 = gevent.spawn(get_page, 'http://www.openstack.org')
    g2 = gevent.spawn(get_page, 'https://www.python.org')
    g3 = gevent.spawn(get_page, 'http://www.sina.com.cn/')
    gevent.joinall([g2, g3])
    
    

    相关文章

      网友评论

          本文标题:协程

          本文链接:https://www.haomeiwen.com/subject/jsgebftx.html