From 36f3ab5798856bbaf8e74e5dc2a04b1624c28e83 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 9 Jan 2014 15:46:55 +0100 Subject: [PATCH] Minor bug fix (for cases when race between thread and main thread is causing server._running to not be set to True) --- lib/request/dns.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/request/dns.py b/lib/request/dns.py index 85d111c06..4c36f8c89 100644 --- a/lib/request/dns.py +++ b/lib/request/dns.py @@ -65,6 +65,7 @@ class DNSServer(object): self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.bind(("", 53)) self._running = False + self._initialized = False def pop(self, prefix=None, suffix=None): """ @@ -91,6 +92,7 @@ class DNSServer(object): def _(): try: self._running = True + self._initialized = True while True: data, addr = self._socket.recvfrom(1024) @@ -116,6 +118,9 @@ if __name__ == "__main__": server = DNSServer() server.run() + while not server._initialized: + time.sleep(0.1) + while server._running: while True: _ = server.pop()