From 875158acd64244eeae431578e3b5a086d5e1f1c2 Mon Sep 17 00:00:00 2001 From: Vratko Polak Date: Tue, 7 May 2019 16:16:06 +0200 Subject: Allow repeated connects on PAPI socket transport The previous implementation fails with RuntimeError("cannot set daemon status of active thread") when a second connect() follows first disconnect(). Change-Id: I671005923eb020130a57b0b484a3386a05d7be33 Signed-off-by: Vratko Polak --- src/vpp-api/python/vpp_papi/vpp_transport_socket.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/vpp-api') diff --git a/src/vpp-api/python/vpp_papi/vpp_transport_socket.py b/src/vpp-api/python/vpp_papi/vpp_transport_socket.py index 63cb6a6e9e7..646bca38983 100644 --- a/src/vpp-api/python/vpp_papi/vpp_transport_socket.py +++ b/src/vpp-api/python/vpp_papi/vpp_transport_socket.py @@ -29,7 +29,7 @@ class VppTransport(object): self.message_table = {} self.sque = multiprocessing.Queue() self.q = multiprocessing.Queue() - self.message_thread = threading.Thread(target=self.msg_thread_func) + self.message_thread = None # Will be set on connect(). def msg_thread_func(self): while True: @@ -69,6 +69,12 @@ class VppTransport(object): def connect(self, name, pfx, msg_handler, rx_qlen): + if self.message_thread.daemon is not None: + raise RuntimeError( + "PAPI socket transport connect: You need to disconnect first.") + self.message_thread.daemon = threading.Thread( + target=self.msg_thread_func) + # Create a UDS socket self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.socket.settimeout(self.read_timeout) @@ -107,6 +113,7 @@ class VppTransport(object): return 0 def disconnect(self): + # TODO: Should we detect if user forgot to connect first? rv = 0 try: # Might fail, if VPP closes socket before packet makes it out rv = self.parent.api.sockclnt_delete(index=self.socket_index) @@ -116,6 +123,8 @@ class VppTransport(object): self.socket.close() self.sque.put(True) # Terminate listening thread self.message_thread.join() + # Allow additional connect() calls. + self.message_thread = None return rv def suspend(self): -- cgit 1.2.3-korg