本文整理汇总了Python中pymongo.pool.get_socket函数的典型用法代码示例。如果您正苦于以下问题:Python get_socket函数的具体用法?Python get_socket怎么用?Python get_socket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_socket函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_over_max_no_timeout_blocks
def test_over_max_no_timeout_blocks(self):
class Thread(threading.Thread):
def __init__(self, pool):
super(Thread, self).__init__()
self.state = 'init'
self.pool = pool
self.sock = None
def run(self):
self.state = 'get_socket'
self.sock = self.pool.get_socket()
self.state = 'sock'
pool = self.get_pool(None, 2, None)
s1 = pool.get_socket()
self.assertTrue(None is not s1)
s2 = pool.get_socket()
self.assertTrue(None is not s2)
self.assertNotEqual(s1, s2)
t = Thread(pool)
t.start()
while t.state != 'get_socket':
time.sleep(0.1)
self.assertEqual(t.state, 'get_socket')
time.sleep(5)
self.assertEqual(t.state, 'get_socket')
pool.maybe_return_socket(s1)
while t.state != 'sock':
time.sleep(0.1)
self.assertEqual(t.state, 'sock')
self.assertEqual(t.sock, s1)
开发者ID:reversefold,项目名称:mongo-python-driver,代码行数:31,代码来源:test_pooling_base.py
示例2: test_wait_queue_timeout
def test_wait_queue_timeout(self):
wait_queue_timeout = 2 # Seconds
pool = self.get_pool_with_wait_queue_timeout(wait_queue_timeout)
pool.get_socket()
start = time.time()
self.assertRaises(ConnectionFailure, pool.get_socket)
duration = time.time() - start
self.assertTrue(
abs(wait_queue_timeout - duration) < 1,
"Waited %.2f seconds for a socket, expected %f" % (
duration, wait_queue_timeout))
开发者ID:MrTravisB,项目名称:mongo-python-driver,代码行数:11,代码来源:test_pooling_base.py
示例3: test_over_max_times_out
def test_over_max_times_out(self):
conn_timeout = 2
pool = self.get_pool(conn_timeout, conn_timeout + 5, conn_timeout)
s1 = pool.get_socket()
self.assertTrue(None is not s1)
s2 = pool.get_socket()
self.assertTrue(None is not s2)
self.assertNotEqual(s1, s2)
start = time.time()
self.assertRaises(socket.timeout, pool.get_socket)
end = time.time()
self.assertTrue(end - start > conn_timeout)
self.assertTrue(end - start < conn_timeout + 5)
开发者ID:reversefold,项目名称:mongo-python-driver,代码行数:13,代码来源:test_pooling_base.py
示例4: test_wait_queue_multiple
def test_wait_queue_multiple(self):
pool = self.get_pool_with_wait_queue_multiple(3)
# Reach max_size sockets.
pool.get_socket()
pool.get_socket()
# Reach max_size * wait_queue_multiple waiters.
threads = []
for _ in xrange(6):
t = SocketGetter(self, pool)
t.start()
threads.append(t)
self.sleep(1)
for t in threads:
self.assertEqual(t.state, 'get_socket')
self.assertRaises(ExceededMaxWaiters, pool.get_socket)
开发者ID:MrTravisB,项目名称:mongo-python-driver,代码行数:19,代码来源:test_pooling_base.py
示例5: __socket
def __socket(self, mongo):
"""Get a SocketInfo from the pool.
"""
pool = mongo['pool']
if self.__auto_start_request:
# No effect if a request already started
self.start_request()
sock_info = pool.get_socket()
if self.__auth_credentials:
self.__check_auth(sock_info)
return sock_info
开发者ID:DanHoerst,项目名称:mongo-python-driver,代码行数:13,代码来源:replica_set_connection.py
示例6: __is_master
def __is_master(self, host):
"""Directly call ismaster.
"""
pool = self.pool_class(host, self.__max_pool_size,
self.__net_timeout, self.__conn_timeout,
self.__use_ssl)
sock_info = pool.get_socket()
response = self.__simple_command(
sock_info, 'admin', {'ismaster': 1}
)
pool.return_socket(sock_info)
return response, pool
开发者ID:DanHoerst,项目名称:mongo-python-driver,代码行数:13,代码来源:replica_set_connection.py
示例7: test_wait_queue_multiple_unset
def test_wait_queue_multiple_unset(self):
pool = self.get_pool_with_wait_queue_multiple(None)
socks = []
for _ in xrange(2):
sock = pool.get_socket()
socks.append(sock)
threads = []
for _ in xrange(30):
t = SocketGetter(self, pool)
t.start()
threads.append(t)
self.sleep(1)
for t in threads:
self.assertEqual(t.state, 'get_socket')
开发者ID:MrTravisB,项目名称:mongo-python-driver,代码行数:14,代码来源:test_pooling_base.py
示例8: __is_master
def __is_master(self, host):
"""Directly call ismaster.
"""
pool = self.pool_class(host, self.__max_pool_size,
self.__net_timeout, self.__conn_timeout,
self.__use_ssl)
sock_info = pool.get_socket()
try:
response = self.__simple_command(
sock_info, 'admin', {'ismaster': 1}
)
pool.maybe_return_socket(sock_info)
return response, pool
except (ConnectionFailure, socket.error):
pool.discard_socket(sock_info)
raise
开发者ID:mobile247,项目名称:mongo-python-driver,代码行数:17,代码来源:replica_set_connection.py
示例9: test_blocking
def test_blocking(self):
# Verify get_socket() with no wait_queue_timeout blocks forever.
pool = self.get_pool_with_wait_queue_timeout(None)
# Reach max_size.
s1 = pool.get_socket()
t = SocketGetter(self, pool)
t.start()
while t.state != 'get_socket':
self.sleep(0.1)
self.sleep(1)
self.assertEqual(t.state, 'get_socket')
pool.maybe_return_socket(s1)
while t.state != 'sock':
self.sleep(0.1)
self.assertEqual(t.state, 'sock')
self.assertEqual(t.sock, s1)
开发者ID:MrTravisB,项目名称:mongo-python-driver,代码行数:19,代码来源:test_pooling_base.py
示例10: test_wait_queue_multiple
def test_wait_queue_multiple(self):
class Thread(threading.Thread):
def __init__(self, pool):
super(Thread, self).__init__()
self.state = 'init'
self.pool = pool
self.sock = None
def run(self):
self.state = 'get_socket'
self.sock = self.pool.get_socket()
self.state = 'sock'
pool = self.get_pool(None, None, None, 3)
socks = []
for _ in xrange(2):
sock = pool.get_socket()
self.assertTrue(sock is not None)
socks.append(sock)
threads = []
for _ in xrange(6):
t = Thread(pool)
t.start()
threads.append(t)
time.sleep(1)
for t in threads:
self.assertEqual(t.state, 'get_socket')
self.assertRaises(ExceededMaxWaiters, pool.get_socket)
while threads:
for sock in socks:
pool.maybe_return_socket(sock)
socks = []
for t in list(threads):
if t.sock is not None:
socks.append(t.sock)
t.join()
threads.remove(t)
开发者ID:reversefold,项目名称:mongo-python-driver,代码行数:37,代码来源:test_pooling_base.py
注:本文中的pymongo.pool.get_socket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论