zoukankan      html  css  js  c++  java
  • urllib3 PoolManager

    A pool manager is an abstraction for a collection of ConnectionPools.
    If you need to make requests to multiple hosts, then you can use a PoolManager, which takes care of maintaining
    your pools so you don’t have to.

    from urllib3 import PoolManager
    
    
    manager = PoolManager(10)
    res = manager.request('GET', 'baidu.com')
    print(res.status)
    print(res.data)

    The PoolManager uses a Least Recently Used (LRU) policy for discarding old pools. That is, if you set the PoolManager
    num_pools to 10, then after making requests to 11 or more different hosts, the least recently used pools will be
    cleaned up eventually.
    Cleanup of stale pools does not happen immediately but can be forced when used as a context manager.

    with PoolManager(10) as manager:
        res = manager.request('GET', 'baidu.com')
        res = manager.request('GET', 'bing.com')

    API

  • 相关阅读:
    sys.stdout.flush-倒计时
    wget 网站扒取
    万能英数脚本
    sample function
    get_time
    读取指定行
    request设置cookies
    resize2fs
    闭包与认识装饰器
    函数的名称空间与作用域
  • 原文地址:https://www.cnblogs.com/shadowwalker/p/5283372.html
Copyright © 2011-2022 走看看