Hi,
I am hosting a UDP server as part of my application on a thread. The problem is when I close the application it doesn't exit completely because the server is still running on the thread.
class pdu_parser(Thread):
run_parser = True
sock = None
def __init__(self):
Thread.__init__(self)
def run(self):
print 'Parser listening on PORT: ', UDP_PORT
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.sock.bind((UUDP_IP, UDP_PORT))
while self.run_parser:
data, addr = self.sock.recvfrom(1024)
self.parse_lt(data)
print '.'
print 'Parser Stopped'
def stopParser(self):
"""
Stop the thread
"""
self.run_parser = False
self.sock.close()
print 'making parser false'
I start the above thread in another objects constructor and i am trying to call the stopParser() method in the destructor.
Please help