From: Martin v. Löwis Date: Sun, 29 Jan 2006 20:10:38 +0000 (+0000) Subject: Try a number of ports, in case 9020 is already in use. X-Git-Tag: v2.5a0~732 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b1e003da8f79a9b8d81ab498cffc49266aa1ac4;p=thirdparty%2FPython%2Fcpython.git Try a number of ports, in case 9020 is already in use. --- diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 54d17a3f0138..16dd93c0c440 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -565,11 +565,23 @@ def test_main_inner(): hdlr.setFormatter(fmt) rootLogger.addHandler(hdlr) + # Find an unused port number + port = logging.handlers.DEFAULT_TCP_LOGGING_PORT + while port < logging.handlers.DEFAULT_TCP_LOGGING_PORT+100: + try: + tcpserver = LogRecordSocketReceiver(port=port) + except socket.error: + port += 1 + else: + break + else: + raise ImportError, "Could not find unused port" + + #Set up a handler such that all events are sent via a socket to the log #receiver (logrecv). #The handler will only be added to the rootLogger for some of the tests - shdlr = logging.handlers.SocketHandler('localhost', - logging.handlers.DEFAULT_TCP_LOGGING_PORT) + shdlr = logging.handlers.SocketHandler('localhost', port) #Configure the logger for logrecv so events do not propagate beyond it. #The sockLogger output is buffered in memory until the end of the test, @@ -585,7 +597,6 @@ def test_main_inner(): #Set up servers threads = [] - tcpserver = LogRecordSocketReceiver() #sys.stdout.write("About to start TCP server...\n") threads.append(threading.Thread(target=runTCP, args=(tcpserver,)))