diff options
Diffstat (limited to 'tcp_async.py')
-rw-r--r-- | tcp_async.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tcp_async.py b/tcp_async.py index d09cf70..5cd4a20 100644 --- a/tcp_async.py +++ b/tcp_async.py @@ -5,7 +5,7 @@ import Queue import time import socket -class TcpAsyncClient(threading.Thread): +class _TcpAsyncClient(threading.Thread): """Thead for message polling""" queue = Queue.Queue() q_quit = Queue.Queue() @@ -14,12 +14,16 @@ class TcpAsyncClient(threading.Thread): port = None BUFFER_SIZE = 1 - def run(self, ip_address = "127.0.0.1", port = 47010): - """connect and poll messages to queue""" - + def __init__(self, ip_address, port): + super(_TcpAsyncClient, self).__init__() self.ip_address = ip_address self.port = port + def __exit__(self): + self.stop() + + def run(self): + """connect and poll messages to queue""" #Establish connection sock = None @@ -55,11 +59,14 @@ class TcpAsyncClient(threading.Thread): class UhdAsyncMsg(object): """Creates a thread to connect to the asynchronous uhd messages tcp port""" - tcpa = TcpAsyncClient() - def __init__(self): + def __init__(self, ip_address = "127.0.0.1", port = 47010): + self.tcpa = _TcpAsyncClient(ip_address, port) self.tcpa.start() + def __exit__(self): + self.tcpa.stop() + def stop(self): """stop tcp thread""" self.tcpa.stop() |