Minor bug fix (for cases when race between thread and main thread is causing server._running to not be set to True)

This commit is contained in:
Miroslav Stampar 2014-01-09 15:46:55 +01:00
parent cb1f17cb04
commit 36f3ab5798

View File

@ -65,6 +65,7 @@ class DNSServer(object):
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._socket.bind(("", 53)) self._socket.bind(("", 53))
self._running = False self._running = False
self._initialized = False
def pop(self, prefix=None, suffix=None): def pop(self, prefix=None, suffix=None):
""" """
@ -91,6 +92,7 @@ class DNSServer(object):
def _(): def _():
try: try:
self._running = True self._running = True
self._initialized = True
while True: while True:
data, addr = self._socket.recvfrom(1024) data, addr = self._socket.recvfrom(1024)
@ -116,6 +118,9 @@ if __name__ == "__main__":
server = DNSServer() server = DNSServer()
server.run() server.run()
while not server._initialized:
time.sleep(0.1)
while server._running: while server._running:
while True: while True:
_ = server.pop() _ = server.pop()