本文整理汇总了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)
示例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)