From 79d91d1f23783f3e98686c79e43ec383f27fe5f7 Mon Sep 17 00:00:00 2001 From: Lutz Rossa Date: Tue, 9 Jan 2018 13:47:33 +0100 Subject: [PATCH] fix a connection timeout bug When connecting to a fast reacting server, if may be possible that the "_communicate" function sends it command earlier than the question for the SECoP version inside the "_inner_run" function. A new variable showing the connection status forces to wait inside "_communicate". Change-Id: Id521bbd53fea9e2e980b9c11b849d36cfdeb1ec2 Signed-off-by: Lutz Rossa Reviewed-on: https://forge.frm2.tum.de/review/17006 Tested-by: JenkinsCodeReview Reviewed-by: Enrico Faulhaber --- secop/client/baseclient.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/secop/client/baseclient.py b/secop/client/baseclient.py index 3ca5490..bbe9742 100644 --- a/secop/client/baseclient.py +++ b/secop/client/baseclient.py @@ -29,6 +29,7 @@ from select import select import threading from collections import OrderedDict +import time import serial # Py2/3 @@ -164,6 +165,7 @@ class Client(object): secop_id = 'unknown' describing_data = {} stopflag = False + connection_established = False def __init__(self, opts, autoconnect=True): if 'testing' not in opts: @@ -234,6 +236,7 @@ class Client(object): while not self.stopflag: line = self.connection.readline() + self.connection_established = True self.log.debug('got answer %r' % line) if line.startswith(('SECoP', 'SINE2020&ISSE,SECoP')): self.log.info('connected to: ' + line.strip()) @@ -467,6 +470,9 @@ class Client(object): # send request msg = self.encode_message(msgtype, spec, data) + while not self.connection_established: + self.log.debug('connection not established yet, waiting ...') + time.sleep(0.1) self.connection.writeline(msg) self.log.debug('sent msg %r' % msg)