Skip to content

Commit 353c13a

Browse files
authored
Merge pull request #20 from crovner/master
Allow connected_socket() to use custom timeout
2 parents 6cf8318 + a3f4dbc commit 353c13a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

haproxyadmin/haproxy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ def __init__(self,
112112
"{}".format(socket_dir))
113113

114114
for _file in glob.glob(os.path.join(socket_dir, '*')):
115-
if is_unix_socket(_file) and connected_socket(_file):
115+
if is_unix_socket(_file) and connected_socket(_file, timeout):
116116
socket_files.append(_file)
117117
elif (socket_file and is_unix_socket(socket_file) and
118-
connected_socket(socket_file)):
118+
connected_socket(socket_file, timeout)):
119119
socket_files.append(os.path.realpath(socket_file))
120120
else:
121121
raise ValueError("UNIX socket file was not set")

haproxyadmin/utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def is_unix_socket(path):
158158

159159
return stat.S_ISSOCK(mode)
160160

161-
def connected_socket(path):
161+
def connected_socket(path, timeout):
162162
"""Check if socket file is a valid HAProxy socket file.
163163
164164
We send a 'show info' command to the socket, build a dictionary structure
@@ -167,13 +167,15 @@ def connected_socket(path):
167167
168168
:param path: file name path
169169
:type path: ``string``
170+
:param timeout: timeout for the connection, in seconds
171+
:type timeout: ``float``
170172
:return: ``True`` is socket file is a valid HAProxy stats socket file False
171173
otherwise
172174
:rtype: ``bool``
173175
"""
174176
try:
175177
unix_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
176-
unix_socket.settimeout(0.1)
178+
unix_socket.settimeout(timeout)
177179
unix_socket.connect(path)
178180
unix_socket.send(six.b('show info' + '\n'))
179181
file_handle = unix_socket.makefile()

0 commit comments

Comments
 (0)