make waiting for the server to start robust
This commit is contained in:
parent
26a1f72637
commit
239f138aea
|
@ -843,17 +843,25 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT):
|
|||
abort = self.abort
|
||||
logging._releaseLock()
|
||||
|
||||
def serve(rcvr, hdlr, port):
|
||||
server = rcvr(port=port, handler=hdlr)
|
||||
class Server(threading.Thread):
|
||||
|
||||
def __init__(self, rcvr, hdlr, port):
|
||||
super(Server, self).__init__()
|
||||
self.rcvr = rcvr
|
||||
self.hdlr = hdlr
|
||||
self.port = port
|
||||
self.ready = threading.Event()
|
||||
|
||||
def run(self):
|
||||
server = self.rcvr(port=self.port, handler=self.hdlr)
|
||||
self.ready.set()
|
||||
global _listener
|
||||
logging._acquireLock()
|
||||
_listener = server
|
||||
logging._releaseLock()
|
||||
server.serve_until_stopped()
|
||||
|
||||
return threading.Thread(target=serve,
|
||||
args=(ConfigSocketReceiver,
|
||||
ConfigStreamHandler, port))
|
||||
return Server(ConfigSocketReceiver, ConfigStreamHandler, port)
|
||||
|
||||
def stopListening():
|
||||
"""
|
||||
|
|
|
@ -1574,7 +1574,7 @@ class ConfigDictTest(BaseTest):
|
|||
port = find_unused_port()
|
||||
t = logging.config.listen(port)
|
||||
t.start()
|
||||
time.sleep(0.5) # give server thread some time to get ready
|
||||
t.ready.wait()
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(2.0)
|
||||
|
|
Loading…
Reference in New Issue