Implicitly close sockets in destructor methods

This commit is contained in:
Thomas Arthofer
2015-05-17 17:08:03 +02:00
parent 2a29e13975
commit 3ceb1e1135

View File

@@ -149,6 +149,9 @@ class TCPSocketConnection(Connection):
def write(self, data): def write(self, data):
self.socket.send(data) self.socket.send(data)
def __del__(self):
self.socket.close()
class UDPSocketConnection(Connection): class UDPSocketConnection(Connection):
def __init__(self, addr, timeout=3): def __init__(self, addr, timeout=3):
@@ -176,3 +179,6 @@ class UDPSocketConnection(Connection):
if isinstance(data, Connection): if isinstance(data, Connection):
data = bytearray(data.flush()) data = bytearray(data.flush())
self.socket.sendto(data, self.addr) self.socket.sendto(data, self.addr)
def __del__(self):
self.socket.close()