@@ -31,19 +31,22 @@ class _HAProxyProcess:
3131 HAProxy process using UNIX stats socket.
3232
3333 :param socket_file: Full path of socket file.
34- :type socket_file: string
34+ :type socket_file: `` string``
3535 :param retry: (optional) Number of connect retries (defaults to 3)
36- :type retry: integer
36+ :type retry: `` integer``
3737 :param retry_interval: (optional) Interval time in seconds between retries
3838 (defaults to 2)
39- :type retry_interval: integer
39+ :param timeout: timeout for the connection
40+ :type timeout: ``float``
41+ :type retry_interval: ``integer``
4042 """
41- def __init__ (self , socket_file , retry = 3 , retry_interval = 2 ):
43+ def __init__ (self , socket_file , retry = 3 , retry_interval = 2 , timeout = 1 ):
4244 self .socket_file = socket_file
4345 self .hap_stats = {}
4446 self .hap_info = {}
4547 self .retry = retry
4648 self .retry_interval = retry_interval
49+ self .timeout = timeout
4750 # process number associated with this object
4851 self .process_nb = self .metric ('Process_num' )
4952
@@ -73,15 +76,10 @@ def command(self, command, full_output=False):
7376 # any other value means retry N times
7477 attempt = self .retry + 1
7578 while attempt != 0 :
79+ print (time .ctime (), attempt , self .retry )
7680 try :
7781 unix_socket = socket .socket (socket .AF_UNIX , socket .SOCK_STREAM )
78- # I haven't seen a case where a running process which holds a
79- # UNIX socket will take more than few nanoseconds to accept a
80- # connection. But, I have seen cases where it takes ~0.5secs
81- # to get a respone from the socket. Thus I hard-code a timeout
82- # of 0.5ms
83- # TODO: consider having a configuration file for it
84- unix_socket .settimeout (0.5 )
82+ unix_socket .settimeout (self .timeout )
8583 unix_socket .connect (self .socket_file )
8684 unix_socket .send (six .b (command + '\n ' ))
8785 file_handle = unix_socket .makefile ()
0 commit comments