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
|
abort = self.abort
|
||||||
logging._releaseLock()
|
logging._releaseLock()
|
||||||
|
|
||||||
def serve(rcvr, hdlr, port):
|
class Server(threading.Thread):
|
||||||
server = rcvr(port=port, handler=hdlr)
|
|
||||||
global _listener
|
|
||||||
logging._acquireLock()
|
|
||||||
_listener = server
|
|
||||||
logging._releaseLock()
|
|
||||||
server.serve_until_stopped()
|
|
||||||
|
|
||||||
return threading.Thread(target=serve,
|
def __init__(self, rcvr, hdlr, port):
|
||||||
args=(ConfigSocketReceiver,
|
super(Server, self).__init__()
|
||||||
ConfigStreamHandler, port))
|
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 Server(ConfigSocketReceiver, ConfigStreamHandler, port)
|
||||||
|
|
||||||
def stopListening():
|
def stopListening():
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1574,7 +1574,7 @@ class ConfigDictTest(BaseTest):
|
||||||
port = find_unused_port()
|
port = find_unused_port()
|
||||||
t = logging.config.listen(port)
|
t = logging.config.listen(port)
|
||||||
t.start()
|
t.start()
|
||||||
time.sleep(0.5) # give server thread some time to get ready
|
t.ready.wait()
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.settimeout(2.0)
|
sock.settimeout(2.0)
|
||||||
|
|
Loading…
Reference in New Issue