diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-02-06 22:08:15 +0000 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-02-06 22:08:15 +0000 |
commit | 85eb0484a44a3fc803aa6ffd445ca8dac817a1aa (patch) | |
tree | c3553f675513866424846fd07a4c014e495aafb4 /Lib/logging | |
parent | dcfdf2978bd813277a686d16d75fa100f848b266 (diff) | |
download | cpython-85eb0484a44a3fc803aa6ffd445ca8dac817a1aa.tar.gz |
make waiting for the server to start robust
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/config.py | 28 |
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(): """ |