Do not add None to samples in case of connection error
Otherwise we get `TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'` when calculating the average.
This commit is contained in:
@@ -151,6 +151,7 @@ AS $$
|
||||
|
||||
t_start = timer()
|
||||
samples = []
|
||||
n_errors = 0
|
||||
|
||||
for i in xrange(n_samples):
|
||||
try:
|
||||
@@ -159,13 +160,13 @@ AS $$
|
||||
s.shutdown(socket.SHUT_RD)
|
||||
except (socket.timeout, OSError, socket.error), ex:
|
||||
plpy.warning('could not connect to server %s:%d, %s' % (host, port, str(ex)))
|
||||
samples.append(None)
|
||||
n_errors += 1
|
||||
|
||||
t_connect = (t_stop - t_start) * 1000.0
|
||||
plpy.debug('TCP connection %s:%d time=%.2f ms' % (host, port, t_connect))
|
||||
samples.append(t_connect)
|
||||
|
||||
return sum(samples) / n_samples
|
||||
return sum(samples) / len(samples)
|
||||
$$
|
||||
LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user