From 3da4c4bcaba549b27f3f3ba69ad7e58a585d5461 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 6 Sep 2007 03:57:23 +0000 Subject: Use an event variable to wait for the server to be ready, not time.sleep(). --- Lib/test/test_ftplib.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 9298bf4..62aae05 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -6,12 +6,13 @@ import time from unittest import TestCase from test import test_support -def server(evt): +def server(evt, ready): serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serv.settimeout(3) serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) serv.bind(("", 9091)) serv.listen(5) + ready.set() try: conn, addr = serv.accept() except socket.timeout: @@ -28,8 +29,9 @@ class GeneralTests(TestCase): def setUp(self): ftplib.FTP.port = 9091 self.evt = threading.Event() - threading.Thread(target=server, args=(self.evt,)).start() - time.sleep(.1) + ready = threading.Event() + threading.Thread(target=server, args=(self.evt, ready)).start() + ready.wait() def tearDown(self): self.evt.wait() -- cgit v0.12