Skip to content

Commit 12b2276

Browse files
opapyopapy
authored andcommitted
set socket._GLOBAL_DEFAULT_TIMEOUT as default value for telnet
1 parent 0d89752 commit 12b2276

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

django_elastipymemcache/cluster_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import re
55
from distutils.version import StrictVersion
6+
import socket
67
from telnetlib import Telnet
78

89
from django.utils.encoding import smart_text
@@ -18,7 +19,7 @@ def __init__(self, cmd, response):
1819
'Unexpected response {} for command {}'.format(response, cmd))
1920

2021

21-
def get_cluster_info(host, port, timeout=None):
22+
def get_cluster_info(host, port, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
2223
"""
2324
return dict with info about nodes in cluster and current version
2425
{
@@ -29,7 +30,7 @@ def get_cluster_info(host, port, timeout=None):
2930
'version': '1.4.4'
3031
}
3132
"""
32-
client = Telnet(host, int(port), timeout=None)
33+
client = Telnet(host, int(port), timeout=timeout)
3334
client.write(b'version\n')
3435
res = client.read_until(b'\r\n').strip()
3536
version_list = res.split(b' ')

django_elastipymemcache/memcached.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def __init__(self, server, params):
5050

5151
# Patch for django<1.11
5252
self._options = self._options or dict()
53-
self._cluster_timeout = self._options.get('cluster_timeout')
53+
self._cluster_timeout = self._options.get(
54+
'cluster_timeout', socket._GLOBAL_DEFAULT_TIMEOUT)
5455

5556
def clear_cluster_nodes_cache(self):
5657
"""clear internal cache with list of nodes in cluster"""

tests/test_backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import socket
12
import sys
23

34
from django.conf import global_settings, settings
@@ -25,7 +26,7 @@ def test_split_servers(get_cluster_info):
2526
}
2627
backend._lib.Client = Mock()
2728
assert backend._cache
28-
get_cluster_info.assert_called_once_with('h', '0', None)
29+
get_cluster_info.assert_called_once_with('h', '0', socket._GLOBAL_DEFAULT_TIMEOUT)
2930
backend._lib.Client.assert_called_once_with(servers, ignore_exc=True)
3031

3132

@@ -48,7 +49,7 @@ def test_node_info_cache(get_cluster_info):
4849
eq_(backend._cache.get.call_count, 2)
4950
eq_(backend._cache.set.call_count, 2)
5051

51-
get_cluster_info.assert_called_once_with('h', '0', None)
52+
get_cluster_info.assert_called_once_with('h', '0', socket._GLOBAL_DEFAULT_TIMEOUT)
5253

5354

5455
@patch('django.conf.settings', global_settings)

0 commit comments

Comments
 (0)