@@ -22,7 +22,14 @@ def _get_socket():
2222
2323
2424class TCPSendSocket (object ):
25- def __init__ (self , tcp_port , tcp_ip = 'localhost' , send_type = NUMPY , verbose = True , as_server = True , include_time = False ):
25+ def __init__ (self ,
26+ tcp_port ,
27+ tcp_ip = 'localhost' ,
28+ send_type = NUMPY ,
29+ verbose = True ,
30+ as_server = True ,
31+ include_time = False ,
32+ as_daemon = True ):
2633 """
2734 A TCP socket class to send data to a specific port and address.
2835 :param tcp_port: TCP port to use.
@@ -36,6 +43,7 @@ def __init__(self, tcp_port, tcp_ip='localhost', send_type=NUMPY, verbose=True,
3643 :param as_server: Whether to run this socket as a server (default: True) or client. When run as a server, the
3744 socket supports multiple clients and sends each message to every connected client.
3845 :param include_time: Appends time.time() value when sending the data message.
46+ :param as_daemon: runs the underlying threads as daemon.
3947 """
4048 self .send_type = send_type
4149 self .data_to_send = b'0'
@@ -48,8 +56,8 @@ def __init__(self, tcp_port, tcp_ip='localhost', send_type=NUMPY, verbose=True,
4856 self .as_server = as_server
4957 self .include_time = include_time
5058 self .connected_clients = []
51- self ._gather_connections_thread = Thread (target = self ._gather_connections )
52- self .sending_thread = Thread (target = self ._run )
59+ self ._gather_connections_thread = Thread (target = self ._gather_connections , daemon = as_daemon )
60+ self .sending_thread = Thread (target = self ._run , daemon = as_daemon )
5361
5462 def send_data (self , data ):
5563 """
@@ -242,7 +250,8 @@ def __init__(self,
242250 verbose = True ,
243251 as_server = False ,
244252 receive_as_raw = False ,
245- receive_buffer_size = 4095 ):
253+ receive_buffer_size = 4095 ,
254+ as_daemon = True ):
246255 """
247256 Receiving TCP socket to be used with TCPSendSocket.
248257 :param tcp_port: TCP port to use.
@@ -257,6 +266,7 @@ def my_handler(received_data):
257266 whatever the SendSocket is configured to be.
258267 :param receive_as_raw: Whether or not the incoming data is just raw bytes or is a predefined format (JSON, NUMPY, HDF)
259268 :param receive_buffer_size: available buffer size in bytes when receiving messages
269+ :param as_daemon: runs underlying threads as daemon.
260270 """
261271 self .receive_buffer_size = receive_buffer_size
262272 self .receive_as_raw = receive_as_raw
@@ -274,9 +284,9 @@ def pass_func(data):
274284 self ._new_data = None
275285 self ._new_data_lock = Lock ()
276286 self .new_data_flag = Event ()
277- self .handler_thread = Thread (target = self ._handler , daemon = True )
287+ self .handler_thread = Thread (target = self ._handler , daemon = as_daemon )
278288 self .socket = _get_socket ()
279- self .thread = Thread (target = self ._run , daemon = True )
289+ self .thread = Thread (target = self ._run , daemon = as_daemon )
280290 self .port = int (tcp_port )
281291 self .ip = tcp_ip
282292 self .block_size = 0
@@ -289,8 +299,7 @@ def pass_func(data):
289299 def start (self , blocking = False ):
290300 """
291301 Start the socket service.
292- :param blocking: Will block the calling thread until a connection is established to at least one receiver.
293- :return: Nothing
302+ :param blocking: Will block the calling thread until a connection is established.
294303 """
295304 self .thread .start ()
296305 if blocking :
0 commit comments