summaryrefslogtreecommitdiff
path: root/Lib/logging
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-02-06 22:08:15 +0000
committerBenjamin Peterson <benjamin@python.org>2010-02-06 22:08:15 +0000
commit85eb0484a44a3fc803aa6ffd445ca8dac817a1aa (patch)
treec3553f675513866424846fd07a4c014e495aafb4 /Lib/logging
parentdcfdf2978bd813277a686d16d75fa100f848b266 (diff)
downloadcpython-85eb0484a44a3fc803aa6ffd445ca8dac817a1aa.tar.gz
make waiting for the server to start robust
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/config.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index d7f7481fe8..1145e71190 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -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)
- global _listener
- logging._acquireLock()
- _listener = server
- logging._releaseLock()
- server.serve_until_stopped()
+ 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():
"""