当前位置: 首页>>代码示例>>Python>>正文


Python HTTPConnectionPool._get_conn方法代码示例

本文整理汇总了Python中urllib3.connectionpool.HTTPConnectionPool._get_conn方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPConnectionPool._get_conn方法的具体用法?Python HTTPConnectionPool._get_conn怎么用?Python HTTPConnectionPool._get_conn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib3.connectionpool.HTTPConnectionPool的用法示例。


在下文中一共展示了HTTPConnectionPool._get_conn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_pool_edgecases

# 需要导入模块: from urllib3.connectionpool import HTTPConnectionPool [as 别名]
# 或者: from urllib3.connectionpool.HTTPConnectionPool import _get_conn [as 别名]
    def test_pool_edgecases(self):
        pool = HTTPConnectionPool(host='localhost', maxsize=1, block=False)

        conn1 = pool._get_conn()
        conn2 = pool._get_conn() # New because block=False

        pool._put_conn(conn1)
        pool._put_conn(conn2) # Should be discarded

        self.assertEqual(conn1, pool._get_conn())
        self.assertNotEqual(conn2, pool._get_conn())

        self.assertEqual(pool.num_connections, 3)
开发者ID:09Hero,项目名称:urllib3,代码行数:15,代码来源:test_connectionpool.py

示例2: test_max_connections

# 需要导入模块: from urllib3.connectionpool import HTTPConnectionPool [as 别名]
# 或者: from urllib3.connectionpool.HTTPConnectionPool import _get_conn [as 别名]
    def test_max_connections(self):
        pool = HTTPConnectionPool(host='localhost', maxsize=1, block=True)

        pool._get_conn(timeout=0.01)

        try:
            pool._get_conn(timeout=0.01)
            self.fail("Managed to get a connection without EmptyPoolError")
        except EmptyPoolError:
            pass

        try:
            pool.request('GET', '/', pool_timeout=0.01)
            self.fail("Managed to get a connection without EmptyPoolError")
        except EmptyPoolError:
            pass

        self.assertEqual(pool.num_connections, 1)
开发者ID:09Hero,项目名称:urllib3,代码行数:20,代码来源:test_connectionpool.py


注:本文中的urllib3.connectionpool.HTTPConnectionPool._get_conn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。